tags:

views:

97

answers:

5

I'm making a shopping mall website using Yahoo solution. I have multiple options for items and some items have different price dependent on the options. Yahoo doesn't support multiple price option and therefore I try to find a solution for this problem. One of my idea 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 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 different price. I'm a novice to JS. Could anyone help me? Thanks in advance.

PS

I'm using javascript to generate options dependent on 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>')

-->

A: 
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.

Rohan
MDC advises to use `window.location` over `document.location` for best cross-browser compatibility. https://developer.mozilla.org/En/Document.location
Andy E
Could you specify where I have to insert the code above? I'm a real novie to JS. Thanks a lot
neko
A: 

You can achieve this using location object location.href = "http://someurl";

Yurec
+5  A: 
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>
Vivin Paliath
ok, it seems like it's not a difficult problem. Almost everybody suggest same solution. I'm a real novice to JS. So could you specify where I have to insert that code?
neko
I posted some sample code that uses an *onChange* event on a *select* to redirect you to the appropriate page.
Vivin Paliath
Hello VivinDid you check my code? The options are dynamically generated by javascript. 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>Could you tell me what to do in this case?
neko
You'll have to perform the redirect in the *listboxchange* function. Since you're passing in the value, you can check to see if it's "500". If it is, redirect.
Vivin Paliath
I'm really sorry but I don't really understand what you mean. If you don't mind, could you modify above code for me?
neko
In the source for your page, check out line 54. That's where the *listboxchange* function has been defined. In that function, you need to check the value of *p_index*. If it is the value that you want, you will set *window.location* to the new URL.By the way, if you're happy with the answer I recommend accepting it. It'll give you a good accept rate which will make others more inclined to answer any future questions.
Vivin Paliath
A: 

You can append the values in query string for 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 button click like this:

<input type="button" onclick="document.location.href = 'your_page.php?var1=value1&var2=value2';">
Sarfraz
-1 He wants to redirect using Javascript, not pass parameters into another page.
Vivin Paliath
@vivin: i have also shown that a bit below, please review again. Thanks
Sarfraz
Saw your change and tried to upvote, but says it's too old.
Vivin Paliath
A: 

you can call a javascript function and use window.location = 'url' ;

http://www.pageresource.com/jscript/jredir.htm

Ravia