...

View Full Version : checkbox and text



kcl
04-03-2003, 08:29 AM
How do i check if checkbox is checked then text is empty or not??

this is my rule:
if i didn't check checkbox then text can be empty,but if i checked checkbox,then text must be filled

i write like this,but it not working.

if (!theForm.Pagehot[0].checked){
if (theForm.DownDate.value == ""){
alert("下架日期請勿空白!!");
theForm.DownDate.value = "";
theForm.DownDate.focus();
return false;
}
}

How do I write??
thanks for reply

HairyTeeth
04-03-2003, 11:12 AM
if (!theForm.Pagehot[0].checked){
if (theForm.DownDate.value == ""){


! = NOT. Therefore, you are are saying 'if theForm.Pagehot[0] IS NOT CHECKED'...when you want it checked. Try this demo(just change the form element references):


<html>
<head>
<title>Untitled</title>
<script type="text/jav&#97;script">
<!--;

function validate(f){
if(f.chk.checked && f.txt.value==""){
alert("You must enter text into the textbox if the checkbox is selected");
f.txt.focus();
return false;
}
return true;
}
//-->
</script>
</head>
<body>
<form action="jav&#97;script:alert('Success')" method="post" onsubmit="return validate(this)">
<input type="checkbox" name="chk" />Checkbox
<br />
<input type="text" name="txt"/>
<br />
<input type="submit" value="Submit" />
</form>
</body>
</html>

kcl
04-03-2003, 11:24 AM
It's working now..

thanks a lot



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum