Hi all,
I need a simple script to give an error popup message when user hits submit without filling in certain textboxes and 1 checkbox. I have a script that successfully pops up an error when any of the required textboxes are empty, but
problem 1: in firefox after the error popup the form proceeds to my 'submission successful' url. It needs to stop the form instead and return focus to the field in question. (ie does this fine.)
problem 2: i can't get an error popup for the required checkbox - the form proceeds as if it were not required.
Here is the function:
...and my form code:
Can anyone lend a hand? I'm not writing my own js yet so I'm a bit clueless.
Thanks!
I need a simple script to give an error popup message when user hits submit without filling in certain textboxes and 1 checkbox. I have a script that successfully pops up an error when any of the required textboxes are empty, but
problem 1: in firefox after the error popup the form proceeds to my 'submission successful' url. It needs to stop the form instead and return focus to the field in question. (ie does this fine.)
problem 2: i can't get an error popup for the required checkbox - the form proceeds as if it were not required.
Here is the function:
Code:
function IsFormComplete(FormName)
{
var x = 0
var FormOk = true
while ((x < document.forms[FormName].elements.length) && (FormOk))
{
if (document.forms[FormName].elements[x].value == '')
{
alert('Please enter your '+document.forms[FormName].elements[x].name +' and try again.')
document.forms[FormName].elements[x].focus()
FormOk = false
}
x ++
}
return FormOk
}
...and my form code:
Code:
<FORM name="form1" method="post" action="/cgi-bin/form/trafficrelief/form.cgi"><div id="form1" align="right">
<input id="name" type="text" name="name" size="25" tabindex="1" /><br />
<input id="org" type="text" name="org" size="25" tabindex="2" value=" " /><br />
<input id="email" type="text" name="email" size="25" tabindex="3" /><br />
<input id="address" type="text" name="address" size="25" tabindex="4" value=" " /><br />
<input id="zip" type="text" name="zip" size="25" tabindex="5" /><br />
<input id="phone" type="text" name="phone" size="25" tabindex="6" value=" " /><br />
<input id="comments" type="text" name="comments" size="25" tabindex="7" value=" " /><br />
<input id="submit" type="image" src="images/submit.gif" name="submit" tabindex="9" OnClick=IsFormComplete("form1")>
</div>
<input name="endorse" type="checkbox" id="endorse" tabindex="8" value="I_ENDORSE" />
<INPUT TYPE="HIDDEN" NAME="data_order"
VALUE="name,org,email,address,zip,phone,comments,endorse">
<INPUT TYPE="HIDDEN" NAME="submit_to" VALUE="web@transalt.org">
<INPUT TYPE="HIDDEN" NAME="automessage" VALUE="mymessage">
<INPUT TYPE="HIDDEN" NAME="outputfile" VALUE="coalition">
<INPUT TYPE="HIDDEN" NAME="countfile" VALUE="coalition">
<INPUT TYPE="HIDDEN" NAME="emailfile" VALUE="coalition">
<INPUT TYPE="HIDDEN" NAME="form_id" VALUE="Citywide Coalition for Traffic Relief">
<INPUT TYPE="HIDDEN" NAME="ok_url"
VALUE="[URL unfurl="true"]http://...">[/URL]
<INPUT TYPE="HIDDEN" NAME="not_ok_url"
VALUE="[URL unfurl="true"]http://...">[/URL]
</form>
Can anyone lend a hand? I'm not writing my own js yet so I'm a bit clueless.
Thanks!