View Full Version : checkbox and text

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 == ""){
theForm.DownDate.value = "";
return false;

How do I write??
thanks for reply

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):

<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");
return false;
return true;
<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" />

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

thanks a lot

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum