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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A TextBox Should Be Filled In 1

Status
Not open for further replies.

damipera

Technical User
Dec 1, 2005
134
GB
hi guys,

i have a form with 3 textboxes, how do i make sure that at least one of the 3 textboxes have been filled in when a user clicks a submit button?

Thanks for any input.
 
hi ggriffit,

this is my form

Code:
<form name="myform">
<p><textarea id="textarea1"></textarea></p>
<p><textarea id="textarea2"></textarea></p>
<p><textarea id="textarea3"></textarea></p>
<p><input name="submit" type="submit" value="submit" /></p>
</form>

thanks for your help
 
HTML:
<form name="myform" [b]onsubmit="return checkTextAreas();"[/b]>
<p><textarea id="textarea1"></textarea></p>
<p><textarea id="textarea2"></textarea></p>
<p><textarea id="textarea3"></textarea></p>
<p><input name="submit" type="submit" value="submit" /></p>
</form>

Code:
<script type="text/javascript">
function checkTextAreas()
{
[indent]var txtArea1 = document.getElementById('textarea1');[/indent]
[indent]var txtArea2 = document.getElementById('textarea2');[/indent]
[indent]var txtArea3 = document.getElementById('textarea3');[/indent]

[indent]if(txtArea1.value=='' && txtArea2.value=='' && txtArea3.value=='')[/indent]
[indent]{[/indent]
[indent][/indent][indent]alert("Error!: At least 1 textarea must be filled in!");[/indent]
[indent][/indent][indent]return false;[/indent]
[indent]}[/indent]
[indent]else[/indent]
[indent]{[/indent]
[indent]return true;[/indent]
[indent]}[/indent]
}
</script>

If all are empty, it does not submit. If at least 1 is not empty, it will allow the submission.


----------------------------------
Phil AKA Vacunita
----------------------------------
OS-ception: Running Linux on a Virtual Machine in Windows which itself is running in a Virtual Machine on Mac OSx.

Web & Tech
 
hi vacunita, as always. YOU ARE AWESOME! thanks very much
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top