Click to See Complete Forum and Search --> : Please help a newbie


smugli
01-11-2003, 09:55 AM
Please could someone help a beginner with this.

I would like to get the code to be able to do the problem below.

Create an html document with a form with a text box and a submit button that submits to http://www.xnu.com/formtest.asp.

Use the onSubmit event so that the form is only submitted when a number has been entered into the text box.

smugli
01-11-2003, 11:01 AM
Sorry about being so vague, it is an assignment, i have the form and submit button set up but i cant get the number to submit to the address, heres what ive got so far.

<HTML>
<HEAD>
<TITLE>Web Page containing JavaScript</TITLE>
<SCRIPT LANGUAGE="JAVASCRIPT"></SCRIPT>
</HEAD>
<BODY>
<FORM NAME="Form1">
Number: <INPUT TYPE="TEXT" NUMBER="Number"><BR>
<INPUT TYPE="Button" VALUE="Submit Info" >
<FORM action="http://www.xnu.com/formtest.asp" onSubmit="return checkform();">
</FORM>
</BODY>
</HTML>

escaperanger
01-11-2003, 11:46 AM
You have placed two <FORM> tags in your code. Seeing as this is an assignment, I assume you have a text book to refer to. Review the proper way to write a <FORM> tag. You will see that all the attributes (name, action, onsubmit) need to be in the same tag.

Can't say I have tried to check a text area to make sure the content is a string or a number. I have a few ideas on where you can start, but I do not know exactly what you are studying. So again, check out your text book to see what suggestions it has for validating form data.

Hope that helps some.

swon
01-11-2003, 11:46 AM
Hi smugli, try out that code:

<HTML>
<HEAD>
<TITLE>Web Page containing JavaScript</TITLE>
<SCRIPT LANGUAGE="JAVASCRIPT">
function checking(form){
str = form.Number.value;
for (i = 0; i < str.length; i++) {
var Zahl1 = str.substring(i);
if (Zahl1 < "0" || "9" < Zahl1) {
alert(str.substring(i,i+1)+" is not a Number");
return false;
}
}
}
</SCRIPT>
</HEAD>
<BODY>
<FORM NAME="Form1" action="http://www.xnu.com/formtest.asp" onSubmit="return checking(this)">
Number:<br>
<INPUT TYPE="TEXT" name="Number"><BR>
<INPUT TYPE="Submit" VALUE="Submit Info">
</FORM>
</BODY>
</HTML>

swon
01-11-2003, 05:40 PM
Use the onSubmit event so that the form is only submitted when a number has been entered into the text box.

that's what smugli want, so the script does it :)

smugli
01-12-2003, 09:35 AM
That did the trick, thanks.