PDA

View Full Version : Help with dynamic hyperlinks from dropdown selection list


scott9614
08-09-2003, 09:00 PM
I am using a dropdown list which has the value set to the cost of the item, I use this to update a null field next to the dropdown with the price or "value" and also use it in calculating the total and sales tax. example (<option value="149.95">)

I know that if I change the option value to a string with the url inside, (<option value="http://www.netscape.com">), I can achieve the effect I am looking for . That is, I have a "dynamic" link called "view" that I would like to change based on the users selection from the dropdown. However, if I change the value to a string I loose my calculation functions!

Examples of code would be great, I am still very new to this language!!

Here are a few snippets of my code to give you a better idea what I'm talking about, still not quite sure if I make sense talking about this language!

function ProductView() {
var PicLink="http://www.yahoo.com";
}

<A href="Javascript:window.open[PicLink]">view</A>

<select name="product_case" onchange="order_price()" onchage="ProductView()" tabindex="1">
<option value="0">
<option value="149.95">THE PRODUCT ($149.95)


Ultimately what I would like is....

function ProductView() {
item1_index = document.order.product_case.selectedIndex;
if (document.order.product_case.options[item1_index].value=="149.95");
var PicLink="http://www.yahoo.com";
}

this would allow me to add if statements for all drop down options and change the URL accordingly, i hope...

Again, thanks for your time and help, I'm so frustrated I'm ready to paypall someone!

Scott

scott9614
08-09-2003, 09:59 PM
null

scott9614
08-12-2003, 07:20 AM
Sorry about the null! darn noobs!

Not even sure if is is acceptable to offer money for help, I am only a college student, but I am desperate!

Please Javascript wizards, give me a hand....


Don't forget to post your email address, or you can send it to me if you would prefer....

Thanks,

Scott

Roy Sinclair
08-12-2003, 02:53 PM
You want TWO values to come from ONE option?

Try:

<option value="149.95*http://www.yahoo.com">THE PRODUCT ($149.95)</option>

Then you can use the split function to divide the string from the option into the price portion and the url portion.

cheesebag
08-12-2003, 08:21 PM
There are two general ways to utilize HTML selects: the old-fashioned (HTML) way, and via JavaScript behavior-modification. A select is a complete package, with an associated array of options, each with its own assignable value. When submitted, the server gets the selectname/selected value pair, naturally. But if you're scripting this, there's no need to restrict yourself to one array of values (Select.options[]), using kludges to retrieve more than one piece of data. The Select.selectedIndex integer - set by the user to whatever option is chosen - can be used as a pointer to as many arrays as you need.

-----> user selects option #3
-----> Select.selectedIndex = 2 (JS counts from zero)

var mydata1 = new Array();
mydata1[1] = 'foo'
mydata1[2] = 'bar'
mydata1[3] = 'bla'

var mydata2 = new Array();
mydata2[1] = 'hoo'
mydata2[2] = 'hah'
mydata2[3] = 'feh'

Plug that index into both arrays (mydata1, mydata2[index]) and retrieve both 'bar' and 'hah' in one swell foop. Use as many arrays as you need to hold different groups of ordered data. Also leaves the [i]actual Option.value property open for the data you'd like sent to the server.