Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    kcl
    kcl is offline
    New to the CF scene
    Join Date
    Feb 2003
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    checkbox and text

    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("U[ФŪť!!");
    theForm.DownDate.value = "";
    theForm.DownDate.focus();
    return false;
    }
    }

    How do I write??
    thanks for reply

  • #2
    Regular Coder
    Join Date
    Mar 2003
    Posts
    176
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: checkbox and text

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

  • #3
    kcl
    kcl is offline
    New to the CF scene
    Join Date
    Feb 2003
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It's working now..

    thanks a lot


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •