tags:

views:

93

answers:

1

Hello everybody. I'm building shopping mall website using Yahoo solution. My products have multiple options which are dependent on previous options. The problem is that in Yahoo, I have to locate options in the order form to appear in checkout page. Nested form doesn't work, of course. Here is one sample page: http://parseven.com/sample-1.html Can anybody help me please?

+2  A: 

Your question is not very clear, but if I understand you correctly what you need is instead of using document.formname.subcategory.options[0] use document.getElementsByName("subcategory")[0].options[0].
document.getElementsByName("subcategory") will return you an array of all element on the page with the name="subcategory", from there you select the first one [0]. After that you can access all of its options.
I would suggest giving your dropdown an id instead of the name. Then you can use document.getElementById("unique-dropdown-id") and that will return you a reference to the select element, instead of array.

Adding more information based on new comments:
In order to make your new example (http://parseven.com/java_ex.html) work without form, remove opening and closing form tags from the page all together. Search for "document.formname.subcategory" and replace it with "document.getElementsByName("subcategory")[0]" and everything will work exactly the same way is it works now.
Since you need to submit your information to Yahoo, you have to keep form tag around, but you can't nest one form tag inside the other. Just leave the Yahoo's form tag intact and remove you other form tag.

Ilya Volodin
`getElementsByName` isn't necessary.
outis
My previous comment looks gruffer than I intended. `document.forms[0].subcategory.options` works as well as `getElementById` would.
outis
I want to change JS in the html. http://parseven.com/java_ex.htmlCould you show me how to get rid of form and still working?
neko
In the yahoo solution, I have to locate the options inside "order form". Otherwise, the options don't show up in the checkout pages. The problem is that this js options are form, and form can not be inside form.Is it clear now?
neko
Thanks a lot, Ilya! You are the best! It works perfect, but I need a little more help. How can I expand more options parseven.com/java_ex.htm? Now I have two drop down options there and I want to have three more. Could you help me? Thanks in advance!
neko
Do exactly the same thing as you've done with the existing two. Attach onchange event to the dropdowns that needs to cause the population of other dropdowns. Give each dropdown unique id (or name, but id is easier to deal with). Create a function for each dropdown and use document.getElementById (if you use id) or document.getElementsByName (if you use name). More or less copy your existing code and change the name of the function and name of the element that you need to add options to.
Ilya Volodin
Ilya, could you look at another file and tell me if it's possible to change same way(switch from form to another)? here is the link:http://parseven.com/test1234.html
neko
Yes, do the following. Open your file, remove form tags. Do a search and replace form.t1 -> document.getElementsByName("t1")[0], form.t2 -> document.getElementsByName("t2")[0]. Repeat the same for form.t3, form.t4, form.t5. Everything should work after that without the form.
Ilya Volodin
Thanks so much Ilya. I'll do it, now.
neko
I just ccopied the file and changed name and I changed what you told me to do. There must be something wrong I did. It doesn't work properly. Could you kindly look at the file I coped and changed and tell me what's wrong? The link is:http://parseven.com/javatest.htmlThanks again.
neko
You missed couple of places. Inside each for loop you are still calling form.t2.length, form.t3.length, etc. Replace those and everything will work fine. Do a search for "form.t"
Ilya Volodin
I corrected and it looks better but miss something. The dropdown options shows only the first options.
neko