PDA

View Full Version : distinguishing submit() from user submit


mdo4
04-28-2003, 04:00 PM
Hello All:


I have a drop down that explicitly calls submit() on the onChange event. I then use the value from this drop down, a list of photography categories, to populate another drop down with a list of sub topics pertaining to the photo category. When a user has made selections for both drop downs, they click the submit button. Problem is, after a user has made both their selections but then decides to change the photography category (first selection), the submit() function forces the post data through when it's not valid because of my onChange event handler. I need a way to determine when my explicit submit() function is called versus the submit made by the user. I've tried hidden fields, but the value is always the same regardless of submission type, I thought about using a reset() instead of a submit() to be called onChange, but I'd lose my post data if I did it that way...does anybody have any ideas on what to do here?

yelena_l
04-28-2003, 06:39 PM
As I understood, both dropdowns are included in one form which is submited. If user decides to change the photography category (first dropdown) at the second time, the selection of the second dropdown must be cleared. So, on the onChange event for the first dropdrown the selectedOption of the second dropdown must be set to nothing:
<form >
<select name="dropdown1" onChange="f1(this)" >...</select>
<select name="dropdown2" >...</select>
...
</form>

<script>
function f1(obj1)
{
var obj2 = obj1.form.elements["dropdown2"]; //second dropdown
obj2.options[obj2.selectedIndex]=-1; //clear the selection from dropdown2
// ... other code
this.form.submit(); // call submit() for the form
}
</script>

Dr. Web
04-28-2003, 07:05 PM
the problem here is that when you submit the form... no matter when, its going on to the action page.

Here is an example of a double combo box, with a submit button at the end (appropriately).

You would use onChange to populate the second select box, and only use submit when the button 'go' is clicked. This should get you in the right direction.