How to make a page redirect using JavaScript? [duplicate]
I'm making a shopping mall website using a Yahoo solution. I have multiple options for items and some items have different price dependent on the options.
Yahoo doesn't support multiple price options, and therefore I try to find a solution for this problem. One of my ideas is to make multiple pages and redirect the page dependent on options. For example, if a customer chose model A, the page will stay in the page A which displays $1000. If a customer chose model B, the page will redirect to the page B which displays $500.
I have already made dynamic options with JavaScript, but I want to modify it to redirect a page. Here is the link of my page:
http://parseven.com/callaway_diabloedge_iron.html
In the page, there are options in the middle. If a customer chose his/her hand, it shows options, "#4 Thru AW," "Lob Wedge," and "Sand Wedge." If a customer chose either "Lob Wedge" or "Sand Wedge', the page has to redirect to a page which has a different price.
PS:
I'm using JavaScript to generate options dependent on the previous option. The code is:
<script type="text/javascript" language="javascript">
<!--
document.write('<select name="Iron(s)" onChange="javascript: listboxchange (this.options[this.selectedIndex].value);"><option value="">Select Iron(s)</option></select>')
-->
</script>
Solution 1:
Use:
window.location = "http://my.url.here";
Here's some quick-n-dirty code that uses jQuery to do what you want. I highly recommend using jQuery. It'll make things a lot more easier for you, especially since you're new to JavaScript.
<select id = "pricingOptions" name = "pricingOptions">
<option value = "500">Option A</option>
<option value = "1000">Option B</option>
</select>
<script type = "text/javascript" language = "javascript">
jQuery(document).ready(function() {
jQuery("#pricingOptions").change(function() {
if(this.options[this.selectedIndex].value == "500") {
window.location = "http://example.com/foo.php?option=500";
}
});
});
</script>
Solution 2:
You can append the values in the query string for the next page to see and process. You can wrap them inside the link tags:
<a href="your_page.php?var1=value1&var2=value2">
You separate each of those values with the &
sign.
Or you can create this on a button click like this:
<input type="button" onclick="document.location.href = 'your_page.php?var1=value1&var2=value2';">
Solution 3:
Use:
document.location.href = "http://yoursite.com" + document.getElementById('somefield');
That would get the value of some text field or hidden field, and add it to your site URL to get a new URL (href). You can modify this to suit your needs.
Solution 4:
You can achieve this using the location
object.
location.href = "http://someurl";