By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,384 Members | 1,794 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,384 IT Pros & Developers. It's quick & easy.

Please hepl

P: 1
I have been teaching myself javascript and i am having a huge problem with this form. All it has to do is check that every field has something in it and then post, but as soon as it gets to the document.getElementById('form1').submit(); it throws an error and say that the object is not supported. Here is the code:

<script language="javascript">
function check_form(){

if(document.getElementById('name').value == ""){
alert("Enter in your name:");
document.getElementById('name').focus();
return;
}

if(document.getElementById('surname').value == ""){
alert("Enter in your surname:");
document.getElementById('surname').focus();
return;
}


if(document.getElementById('email').value == ""){
alert("Enter in your Email Address:");
document.getElementById('email').focus();
return;
}

if(document.getElementById('bname').value == ""){
alert("Enter in your business name:");
document.getElementById('bname').focus();
return;
}

if(document.getElementById('cellno').value == ""){
alert("Enter in your Cellphone number:");
document.getElementById('cellno').focus();
return;
}


if(document.getElementById('Q1').value == ""){
alert("Please answer Question 1:");
document.getElementById('Q1').focus();
return;
}

if(document.getElementById('Q2').value == ""){
alert("Please answer Question 2:");
document.getElementById('Q2').focus();
return;
}

if(document.getElementById('Q3').value == ""){
alert("Please answer Question 3:");
document.getElementById('Q3').focus();
return;
}

document.getElementById('form1').submit();
}

</script>

<table>
<form name="form1" id="form1" action="mailer2.php" method="post">
<tr>
<td colspan="3"><strong>Customer Details</strong></td>
</tr>
<tr>
<td colspan="3">Please fill in the following * textboxes in order to press submit.</td>
</tr>
<tr>
<td colspan="3"><hr color="#CCCCCC" width="660" align="center" /></td>
</tr>
<tr>
<td >*&nbsp;&nbsp;&nbsp;Name:</td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td><input name="name" id="name" type="text" /></td>
</tr>
<tr>
<td >*&nbsp;&nbsp;&nbsp;Surname:</td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td><input name="surname" id="surname" type="text" /></td>
</tr>
<tr>
<td >*&nbsp;&nbsp;&nbsp;Email:</td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td><input name="email" id="email" type="text" /></td>
</tr>
<tr>
<td >*&nbsp;&nbsp;&nbsp;Business Name:</td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td><input name="bname" id="bname" type="text" /></td>
</tr>
<tr>
<td >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Ticket Number:</td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td><input name="ticno" id="ticno" type="text" /></td>
</tr>
<tr>
<td >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Telephone Number:</td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td><input name="telno" id="telno" type="text" /></td>
</tr>
<tr>
<td >*&nbsp;&nbsp;&nbsp;Cellphone Number:</td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td><input name="cellno" id="cellno" type="text" /></td>
</tr>
<tr><td colspan="3">&nbsp;</td></tr>
<tr><td colspan="3">&nbsp;</td></tr>
<tr>
<td colspan="3"><strong>Questionair</strong></td>
</tr>
<tr>
<td colspan="3"><hr color="#CCCCCC" width="660" align="center" /></td>
</tr>
<tr>
<td >1. Were you treated in a friendly manner?</td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;</td>
<td >
<input name="Q1" id="Q1" value="poor" type="radio" />Poor
<input name="Q1" id="Q1" value="average "type="radio" />Average
<input name="Q1" id="Q1" value="good" type="radio" />Good
</td>
</tr>
<tr>
<td colspan="3"><hr color="#CCCCCC" width="660" align="center" /></td>
</tr>
<tr>
<td >2. Was your query attended to quickly and efficiently ?</td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;</td>
<td >
<input name="Q2" id="Q2" value="poor" type="radio" />Poor
<input name="Q2" id="Q2" value="average" type="radio" />Average
<input name="Q2" id="Q2" value="good" type="radio" />Good
</td>
</tr>
<tr>
<td colspan="3"><hr color="#CCCCCC" width="660" align="center" /></td>
</tr>
<tr>
<td >3. Has your query been resolved?</td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;</td>
<td >
<input name="Q3" id="Q3" value="poor" type="radio" />Poor
<input name="Q3" id="Q3" value="average" type="radio" />Average
<input name="Q3" id="Q3" value="good" type="radio" />Good
</td>
</tr>
<tr>
<td colspan="3"><hr color="#CCCCCC" width="660" align="center" /></td>
</tr>
<tr>
<td >4. Do you have any suggestions to improve our service?</td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;</td>
<td >
<textarea cols="25" rows="3" name="Q4" id="Q4"></textarea>
</td>
</tr>
<tr>
<td colspan="3"><hr color="#CCCCCC" width="660" align="center" /></td>
</tr>
<tr>
<td >5. Would you like to hear about Webstorms:</td>
<td align="right" >3G&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;</td>
<td >
<input name="check1" id="check1" value="yes" type="radio" >
</td>
</tr>
<tr>
<td align="right" colspan="2" >ADSL&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;</td>
<td >
<input name="check2" id="check2" value="yes" type="radio" >
</td>
</tr>
<tr>
<td align="right" colspan="2" >Wireless&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;</td>
<td >
<input name="check3" id="check3" value="yes" type="radio" >
</td>
</tr>
<tr>
<td align="right" colspan="2" >I-burst&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;</td>
<td >
<input name="check4" id="check4" value="yes" type="radio" >
</td>
</tr>
<tr>
<td align="right" colspan="2" >Hosting&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;</td>
<td >
<input name="check5" id="check5" value="yes" type="radio" >
</td>
</tr>
<tr>
<td align="right" colspan="2">Web design&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;</td>
<td>
<input name="check6" id="check6" value="yes" type="radio" >
</td>
</tr>
<tr><td colspan="3">&nbsp;</td></tr>
<tr>
<td colspan="3"><hr color="#CCCCCC" width="660" align="center" /></td>
</tr>
<tr><td colspan="3">&nbsp;</td></tr>
<tr>
<td align="right"><input type="button" value="Submit >>" id="submit" name="submit" onclick="check_form();" /></td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;</td>
<td align="left">
<input type="button" value="Reset <<" id="reset" name="reset" /></td>
</tr>
</form>
</table>

It is posting through a PHP page, and its not throwing any errors on that page.

If anyone could help i would be truely grateful.

Tyla
Sep 21 '06 #1
Share this Question
Share on Google+
2 Replies


10K+
P: 13,264
Did not really study your code but I do not see why you are going through the
trouble of using document.getElementById, when the form is being passed from which you can get the input name. Also since the validation is basically the same for all the input boxes, perhaps you do not even have to pass the names of the inputs
Sep 21 '06 #2

ronverdonk
Expert 2.5K+
P: 4,258
I am not sure about the ins and outs of the GetElementById.submit(), but have you tried
[PHP]document.form1.submit();[/PHP]
Ronald :cool:
Sep 21 '06 #3

Post your reply

Sign in to post your reply or Sign up for a free account.