PDA

View Full Version : <Select onChange="document.form.submit();"> doesn't work!!


Bullo
09-12-2002, 09:26 AM
Hi,

I have a drop down box that contains categories read from a database. There is a drop down box below it that has sub categories related to each category.

When the user selects a category I want to be able to submit the form, so that it can select the correct sub categories, and then render the page again.

At the moment my code looks like this:

<form name="addproduct" action="newproduct.asp?where=add" method="post">
<select name="Category" onChange="document.addproduct.submit();">
<option value=" "> </option>
<option value="12" >Clothing</option>
<option value="22" >Kids</option>
<option value="23" >Bike</option>
<option value="24" >Rucksacks</option>
<option value="25" >Sleeping Bags</option>
<option value="44" >Tents</option>
<option value="45" >Markill</option>
</select>
</form>

shvetak
09-12-2002, 10:14 AM
Hi,

Your code is fine. It works. But remember, since you are submitting your form in the onChange event of the dropdown, if you select the same value again from the dropdown, the form will not be submitted.

E.g.
Suppose you have this category dropdown that you just defined, and when you select a category, you want it to submit the form and bring up newproduct.asp with the products belonging to the category. Also if you are showing the Category dropdown again on this page with value selected as the one you chose, then you can only re-submit the form when you select a different category. Because unless you change the value, the onChange event will not fire and your form will not be submitted.

shvetak.

Bullo
09-12-2002, 10:48 AM
Yes, but I get an error saying:

Error: Line 99, Object expected.

Line 99 is the <select onChange....

So why? I don't know at all! Computers! So stressful!!


John.

jolietjake
09-12-2002, 11:00 AM
I try your code and works fine!, perhaps is your navigator. Try writing this:

onChange="javascript:document.addproduct.submit();"

Another idea is that if you're using asp, then the line 99 is different in your asp code than the line 99 in your html generated code. To find errors is better Netscape or Mozilla, it dispends more information about errors.

------------------

Jolietjake Master of Blues & Rythm