hernest42's if code is perfect but the logic is slightly off. You said if the textfield is NULL then send an alert, so the if statement should be:
f.text1.value == ""
- Joe P
Main Topics
Browse All TopicsNeed a working example of javascript checking the value of one field when the value of another field is selected.
For example:
On change of list1, and only when list1 select is set to value "1" for active, check to see if text1 is null. If null, send alert. If not null, do nothing.
Follow this form as an example please.
<form action="submit.asp" name=method="get">
<input name="text1" type="text">
<br><br>
<select name="list1">
<option selected>Select...</option
<option value="1">Active</option>
<option value="2">Test</option>
</select>
<br><br>
<input name="" type="submit" value="Submit">
</form>
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Ok, so I believe you wanted it to check when the selet box changed.... and only if the text box WAS empty when "1" was selected, did you get an alert. Try this instead:
<script>
function checkSelect()
{
if ((document.form1.list1.val
alert('Textbox 1 must be completed');
}
}
</script>
<form name="form1" action="submit.asp" method="get">
<input name="text1" type="text">
<br><br>
<select name="list1" onchange="checkSelect()">
<option selected>Select...</option
<option value="1">Active</option>
<option value="2">Test</option>
</select>
<br><br>
<input name="" type="submit" value="Submit">
</form>
Hope this helps,
LTCJ
Business Accounts
Answer for Membership
by: hernst42Posted on 2007-07-31 at 13:45:54ID: 19604083
Try:
>
<script>
function valform(f)
{
if (f.list1.value =="1" && f.text1.value != "") {
alert('Text must be empty');
return false;
}
return true;
}
</script>
<form action="submit.asp" name=method="get" onsubmit="return valform(this)">
<input name="text1" type="text">
<br><br>
<select name="list1">
<option selected>Select...</option
<option value="1">Active</option>
<option value="2">Test</option>
</select>
<br><br>
<input name="" type="submit" value="Submit">
</form>