SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: Validate

  1. #1
    SitePoint Addict
    Join Date
    Jun 2008
    Posts
    205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Validate

    How to validate if radio button option ==4 and date2.disabled==false ,,,,
    alert message Duration option not available

    Code:
    function checkForm(TheForm) {
            //if((document.example.opt2.value==4) && (document.example.date2.value != "yyyy-mm-dd")){
            //      var msg="select only Start date, duration option not available";
            //      alert(msg);
            //      return false;
            //      }
            if (document.example.date2.disabled == true) {
                    if (document.example.date1.value == "yyyy-mm-dd") {
                            var msg = "date not chosen from calendar icon";
                            alert(msg);
                            return false;
                    }
            }
            else{
                    if (document.example.date1.value == "yyyy-mm-dd" || document.example.date2.value == "yyyy-mm-dd") {
                            var msg = "start or end date not chosen from calendar icon";
                            alert(msg);
                    return false;
                    }
                    if(document.example.date1.value > document.example.date2.value){
                            var msg = "choose proper date-Start date is greater than end date";
                            alert(msg);
                            return false;
                    }
                     if(document.example.date1.value == document.example.date2.value){
                            var msg = "choose proper date-Start and end date is equal";
                            alert(msg);
                            return false;
                    }
    
            }
    }
    
    
    <FORM NAME="example" class="frm" onSubmit="return checkForm(this); submit=”a.php”>
    
      <input type="radio" name="opt2" value="2" checked>
      Option 1<br><br>
      <input type="radio" name="opt2" value="3">
      Option 2<br><br>
      <input type="radio" name="opt2" value="4">
      Option 3<br><br>

  2. #2
    masquerading Nick's Avatar
    Join Date
    Jun 2003
    Location
    East Coast
    Posts
    2,215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What output does your code produce?
    Nick . all that we see or seem, is but a dream within a dream
    Show someone you care, send them a virtual flower.
    Good deals on men's watches

  3. #3
    SitePoint Addict
    Join Date
    Jun 2008
    Posts
    205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Possibility View Post
    What output does your code produce?
    This code is working for all radio button when duration option is selected.
    I just want when only 4th radio button is selected i.e when value =4.
    Code:
    for (var i=0; i < document.example.opt2.length; i++)
       {
       if (document.example.opt2[i].checked && document.example.opt2[i].value==4 && document.example.date2.value != "yyyy-mm-dd"))
    	   
          {
           var msg="select only Start date, duration option not available";
                  alert(msg);
                  return false;
    	
          }
       }

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    First, there are troubles with the form element

    Code html4strict:
    <FORM NAME="example" class="frm" onSubmit="return checkForm(this); submit=”a.php”>

    • The tag and attribute names should be lowercase
    • The onsubmit attribute is missing a closing doublequote
    • The submit attribute should use straight double quotes instead of curly ones


    Code html4strict:
    <form name="example" class="frm" onsubmit="return checkForm(this);" submit="a.php">
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


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
  •