I'm very new to JavaScript, so please forgive my ignorance. I have a form with a dropdown list that picks a product, and a group of option boxes to pick the media that product is available in. Some products are not available in all media (there are a max of 4 types). I've programmed in other languages so I figure what I need to do is read the selected product from the product list, then display (or hide) the media options based on that selection.
The drop down list is product, the radio buttons are media. Where do I put my script? How do I determine which element of the product array was selected? How can I change (or eliminate) an option button/option text?
Thanks so much Willy & Adios. Adios' code looks like its what I need. Will have to try it out before I know if I have more questions. One question I do know I have is that I have to send this resulting choice to a cfm page. If the choice of product is "Volume 1" (item description) and the choice of media is "CD:15.00:2" (second part of the item description:item price:units), how do I send the concatenation of those 2 vars to the cfm page?
Do I store the objects (product.selected.value and media.selected.value) to vars and send the vars? What would the <a href> to the page look like? Right now it goes something like this:
<a href="http://ww4.aitsafe.com/cf/add.cfm?&blueshorts:17.00:2" where "blue shorts" is the item, 17.00 is the price and 2 is the units. I haven't been able to figure out how to expand the vars so the page I'm sending to will understand it.
I'm not using Cold Fusion, just html. I've included (below) the stripped down code, starting at the form tag. I'm using "Blue Shorts" as the product name, 29.50 as the price and 2 as the units. I don't know what to put in the place of these values. My real product name is the value of the selected product (below) plus the value of the first part of the selected media (ie, Book, CD, etc) and the price and units are appended as part of the value of the selected media with colons. This is the format I need to use to send the order to an ecom site. Does this help clear it up?
Location: Los Angeles, CA Original Location: Philippines
Posts: 10,241
Thanks: 0
Thanked 112 Times in 111 Posts
When the form is submitted, the selected items in a combobox and radio button gets submitted to the server. So just retrieve the value of the "product" combobox and the value of "media" radio button in the server-side (cfm) and do the concatenation there.
Thanks so much, Glenn. Its not working, yet, but perhaps you could explain the code to me and I can fix it. What is f.media.length? Media is the name of the option group, so is this the number of options in media? If so, should I substitute the form name for "f."? The debugger is telling me that f.media.length is not an object. Should I replace the "f" in the addparam line, too?
I'm not just looking for someone to write the code for me, I'd like to learn this.
I'm not sure if Glenn is around at this time of day. But f is the form reference. How are you calling the function? Did you add the onsubmit to the form as in his example?
Thanks for your help Willy. Yes, that's exactly how I'm calling the function. Maybe, because its referring to "this", I don't have it in the right place. No, that can't be it, since the function has to be on the start line of the form. Is this something I have to test out by actually running it on my server?
As I said, this refers to the form and that is not your problem. I just ran the codes and they work fine as written provided you are implementing them correctly.
Here is the return:
?productpr=Vol2%3APrintedBook%3A19.50%3A2
Perhaps you should post the codes you are working with so someone could see how you implemented the script....
......Willy
Last edited by Willy Duitt; 06-29-2004 at 01:11 AM..
<td width="66%" colspan="3" align="right"><font size="2"> Handling Charge Per Order
(except e-Books)</font></td>
<td width="31%" valign="bottom" align="center">$4.50</td>