SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: check box

  1. #1
    SitePoint Zealot
    Join Date
    Mar 2011
    Posts
    146
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question check box

    Hi,
    Im trying to nut out a check box validation

    The goal-
    the check box as default is unchecked and when checked validates a text area for text

    Any ideas?


    function checkText() // check box
    {
    if (document.Forders.card.checked == false)//true?
    {}
    if( document.Forders.special.value.length ==0 ||document.Forders.special.value == "Enter your personal message here" )
    {
    alert ( "Please enter your personal message in the text area" );
    return false;
    }
    }

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,192
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    If im following correctly the following is what you want

    Code JavaScript:
    function checkText( ele ) // check box
    {
        var special = document.Forders.special.value;
     
        if ( ele.checked ) // true?
        {
            if ( special.length == 0 || special == "Enter your personal message here" )
            {
                alert( "Please enter your personal message in the text area" );
                return false;
            }
        }
    }

    HTML Code:
    <form action="" method="post" onsubmit="checkText(this.checkboxname)">
    checkboxname referrers to the name of your check box.

  3. #3
    SitePoint Zealot
    Join Date
    Mar 2011
    Posts
    146
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up

    Quote Originally Posted by SgtLegend View Post
    If im following correctly the following is what you want

    Code JavaScript:
    function checkText( ele ) // check box
    {
        var special = document.Forders.special.value;
     
        if ( ele.checked ) // true?
        {
            if ( special.length == 0 || special == "Enter your personal message here" )
            {
                alert( "Please enter your personal message in the text area" );
                return false;
            }
        }
    }

    HTML Code:
    <form action="" method="post" onsubmit="checkText(this.checkboxname)">
    checkboxname referrers to the name of your check box.
    Thanks again for your help

    I was wondering if an if could be put inside an if


Tags for this Thread

Bookmarks

Posting Permissions

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