Jump to content

Validating a textfield once a checkbox is ticked

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
Guest_MAC_*

Guest_MAC_*
  • Guests
Hi
Can anyone help?

I have a simple contact form which I have so far managed to validate, the one function I do not know how to do is this-

If the browser selects the checkbox I need them to fill out a textfield as well(10 digit number to be exact) or the form doesn’t validate, if they de-select or do not select the checkbox I want the form to validate without it.

Hope that makes sense

Thanks MAC

#2
Guest_Jordan_*

Guest_Jordan_*
  • Guests
If you want to do this before the submit button is pressed then you will need to use JavaScript. Here is some sample code:

[COLOR=#ff0000]<script Language="JavaScript">
<!-- 
function Blank_TextField_Validator()
{
// Check the value of the element named text_name
// from the form named text_form
if (text_form.text_name.value == "")
{
// If null display and alert box
alert("Please fill in the text field.");
// Place the cursor on the field for revision
text_form.text_name.focus();
// return false to stop further processing
return (false);
}
// If text_name is not null continue processing
return (true);
}
-->
</script>[/COLOR]

<form name="text_form" method="get" action="http://www.codeave.com/html/get.asp" 
[COLOR=#ff0000] onsubmit="return Blank_TextField_Validator()"[/COLOR]>