Forum Moderators: open
and how do I tell the difference between a button submit and an onchange submit?
Using Javascript, these will each submit the form:
<select onchange="this.form.submit()" ... >
<input type="submit"> (when clicked)
<input type="text" onblur="this.form.submit()" ... > (when they leave this element)
Note that the onchange, onblur, onwhatever events are already Javascript. You do not need (nor want) to reiterate the protocol in such an event. It's like saying "http://http://www.domain.com".
<script>
function setFormSubmitMarker(frm,valu) {
frm.whichSubmit.value=valu;
}
</script>
<form>
<input type="hidden" name="whichSubmit" value="">
<select onchange="setFormSubmitMarker(this.form,'selectmenu');this.form.submit();"> ... </select>
<input type="submit" onclick="setFormSubmitMarker(this.form,'submitbutton')">
</form>
Then, when PHP gets a look at the values being passed by the form, it can see that "whichSubmit" ended up as either "selectmenu" or "submitbutton".
<INPUT Type="hidden" Name="Submit" Value="NoButton">
<INPUT Type="Submit" Name="Submit" Value="Insert this form">
Can I see the difference from a select submittal from a submit button?
Seems like I should be able to look at $_POST['Submit'] and know?
===============
This is still not working:
<SELECT Name="Country" onChange="submit(); return true;" class="large">
I get an error:
Line: 66
Char: 1
Error: Object doesn't support this property or method
Code: 0
URL: [..............php...]
Thanks
<SELECT Name="Country" onChange="submit(); return true;" class="large">
That says "submit this form element" ... which is not what you want:
<SELECT Name="Country" onChange="this.form.submit();" class="large">
That says "submit the form that this element is part of" whis IS what you want. :)
The value of the submit form element is not sent with the form data unless you are using an image as a submit button, in which case x= and y= parameters are passed, indicating where on the image the user clicked.
I recommend modifying the value of the hidden form element as I wrote above because you can assign a value to it before the form is submitted, and it works (a) when the select menu is changed, (b) when the submit button is clicked, and (c) when the submit button is given focus and then the user pressed 'enter'. You'd need to add a function that runs onsubmit to check if the hidden element has a value, and if not, assign it a value of "submitbutton-enter" to distinguish between the clicked button and the keyboard activation:
<script>
function checkSubmitMarker(frm) {
thisform=frm;
if (frm.whichSubmit.value=="") {
setFormSubmitMarker(thisform,'submitbutton-enter');
}
return true;
}
function setFormSubmitMarker(frm,valu) {
frm.whichSubmit.value=valu;
}
</script>
<form onsubmit="return checkSubmitMarker(this)">
<input type="hidden" name="whichSubmit" value="">
<select onchange="setFormSubmitMarker(this.form,'selectmenu');this.form.submit();"> ... </select>
<input type="submit" onclick="setFormSubmitMarker(this.form,'submitbutton-click')">
</form>