Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form Field Requirements

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I'm creating a field (through Frontpage 2000) that will only accept digits. I know this is possible and have seen it many times. I would like my viewers to see a popup message stating, "Field requires digits."
Any suggestions?

f909
 
Try something like this:
Code:
<html>
<head>
<script language=&quot;javascript&quot;>
function validate() {
if (/\D/.test(document.form.field.value)) {
alert(&quot;Field requires digits.&quot;)
return false
}
else {
return true
}
}
</script>
</head>
<body>
<form name=&quot;form&quot; onsubmit=&quot;return validate()&quot;>
<input type=&quot;text&quot; name=&quot;field&quot; /> <input type=&quot;submit&quot; value=&quot;submit&quot; />
</form>
</body>
</html>
 
Just an addition to the question,

Can I have 2 textfields in 2 different forms and the submit button in another form and work together?

A rough skecth of the idea.

Form1
must enter &quot;tek&quot;
else
&quot;Please enter &quot;tek&quot; (case sensitive)

Form2
must enter &quot;tips&quot;
else
&quot;Please enter &quot;tips&quot; (case sensitive)

Form3
Button
onSubmit = check Form1 and Form2 validation
return window.location =&quot;yahoo.com&quot;

Thanks,
soonkhoo
 
I'm not really sure why you'd want to do that, but this code should work...
Code:
<html>
<head>
<script language=&quot;javascript&quot; type=&quot;text/javascript&quot;>
function validate() {
var text1 = document.form1.text1.value
var text2 = document.form2.text2.value
if (text1 != &quot;tek&quot;) {
alert(&quot;Please enter \&quot;tek\&quot; (case sensitive)&quot;)
}
if (text2 != &quot;tips&quot;) {
alert(&quot;Please enter \&quot;tips\&quot; (case sensitive)&quot;)
}
if (text1 == &quot;tek&quot; && text2 == &quot;tips&quot;) {
window.location = &quot;[URL unfurl="true"]http://www.yahoo.com&quot;[/URL]
}
}
</script>
</head>
<body>
<form name=&quot;form1&quot;>
Enter tek: <input type=&quot;text&quot; name=&quot;text1&quot; />
</form>
<form name=&quot;form2&quot;>
Enter tips: <input type=&quot;text&quot; name=&quot;text2&quot; />
</form>
<form name=&quot;form3&quot;>
<input type=&quot;button&quot; value=&quot;Submit&quot; onclick=&quot;validate()&quot; />
</form>
</body>
</html>

Why does there need to be more than one form?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top