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?
-
Where do you want to submit the form to, Yahoo! or your site? Remove the form tag for the one you don't want and be done with it.outis– outis2010-01-30 00:23:36 +00:00Commented Jan 30, 2010 at 0:23
-
I want to submit the form to Yahoo, since Yahoo is the solution.If I remove the form tag, what do I have to replace it? I'm novice to js. Any help will be appreciated.neko– neko2010-01-30 01:33:32 +00:00Commented Jan 30, 2010 at 1:33
1 Answer
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.
12 Comments
getElementsByName isn't necessary.document.forms[0].subcategory.options works as well as getElementById would.