javascript : onblur event and list

Author Message
aashishnakra

  • Total Posts : 1
  • Scores: 0
  • Reward points : 0
  • Joined: 2/10/2009
  • Status: offline
javascript : onblur event and list Monday, March 09, 2009 7:52 AM (permalink)
0
Hi!!
i want to validate a list box onthe onblur event and if no value is selected , display a message on the left using <span> and innerHTML


here's what i have written

 <html>
 <head>
 <script type="text/javascript">
 
 function validateCB()
  {
   if(document.rec.loc.options.selectedIndex = = 0)
    {
     alert(" hi");
     return false;
    }
    else
     return true;
   }
 
 
 function validatePID(inputfield, helptext)
  {
   if(inputfield.value.length !=9)
 `  {
     if(helptext != null)
      helptext.innerHTML = "please enter excatly 9 digits";
      return false;
    }
   else
    {
      if(helptext != null)
      helptext.innerHTML = "";
      return true;
 
   }
 }
 
 </script>
 
 </head>
 
 <form method = "post" action="rec.asp" id="rec" name="rec">
 <table>
  <tr>
  <td>
   <input id='pid' name='pid' onblur="validatePID(this,document.getElementById('pid_help'))">
   <span id ="pid_help" class="help" > </span> <br> <br>
 </td>
 
 
 <td>
 <select id='loc' name='loc' onblur="validateCB()"> <span id="loc_help"> 
 <option value = ' ' selected > select location </option>
 <option value = 'abcd' selected > abcd </option>
 <option value = '1234' selected > 1234 </option>
 </td>
 </table>
 
 </form>
 </html>
 
 


well when i was doing this at work... when i entered less than 9 digits in the PID box..it dispalyed text on the left saying please enter 9 digits.. that's what i want to happen, if a user doesn't select a value from the list as well...i tried writing the code for it..but it didnt' work... so i just wrote the alert code..which was working ..but it isnt' here...
dont' know where am i going wrong...
please help !!
thank's....
 
#1
    TNO

    • Total Posts : 2094
    • Scores: 36
    • Reward points : 0
    • Joined: 12/18/2004
    • Location: Earth
    • Status: offline
    RE: javascript : onblur event and list Thursday, March 12, 2009 9:37 AM (permalink)
    0
     <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
     <html>
         <head>
             <title>Select Box Validation</title>
             <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
     
             <style type="text/css">
     
             </style>
     
             <script type="text/javascript">
                 var myList
                 
                 function validate(){
                     if(myList.selectedIndex == 0){
                         alert("Select something damn you!")
                     }
                 }
                 
                 onload = function(){
                     myList = document.getElementById("myList");
                     myList.onchange = validate;
                 }
             </script>
         </head>
         <body>
             <select id="myList">
                 <option value="0">Choose -- &gt;</option>
                 <option value="1">First</option>
                 <option value="2">Second</option>
                 <option value="3">Third</option>
             </select>
         </body>
     </html>
     


    just change the event handler to whatever you wwant/need it to be
    To iterate is human, to recurse divine. -- L. Peter Deutsch
     
    #2

      Online Bookmarks Sharing: Share/Bookmark

      Jump to:

      Current active users

      There are 0 members and 1 guests.

      Icon Legend and Permission

      • New Messages
      • No New Messages
      • Hot Topic w/ New Messages
      • Hot Topic w/o New Messages
      • Locked w/ New Messages
      • Locked w/o New Messages
      • Read Message
      • Post New Thread
      • Reply to message
      • Post New Poll
      • Submit Vote
      • Post reward post
      • Delete my own posts
      • Delete my own threads
      • Rate post

      2000-2012 ASPPlayground.NET Forum Version 3.9