Forum Moderators: open

Message Too Old, No Replies

Auto Submit Problem

Which should I use and how?

         

HeadBut

4:00 pm on Sep 24, 2004 (gmt 0)

10+ Year Member



I have a <select> menu I want to auto submit when selected. I don't want to run my insert code just want to propogate another select. I can't get either of these to even submit the form:
onChange="javascript:this.form.submit();" onChange="submit(); return true"

and how do I tell the difference between a button submit and an onchange submit?

HeadBut

4:39 pm on Sep 24, 2004 (gmt 0)

10+ Year Member



This should not have been moved to the "Javascript" form. I want to know the PHP solution. How do I tell in PHP how a form is submitted?

StupidScript

7:04 pm on Sep 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Cain't do it with PHP. PHP is server-side only, and has no idea what a user is doing until the doc is requested from the server.

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".

StupidScript

7:10 pm on Sep 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you want to inform PHP of HOW the form was submitted, then you still need to use Javascript:

<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".

HeadBut

9:57 pm on Sep 24, 2004 (gmt 0)

10+ Year Member



Will this work:

<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

StupidScript

11:22 pm on Sep 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's a question of what you are trying to submit:

<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>