473,324 Members | 2,246 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

list and onblur event..

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

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4.  
  5. function validateCB()
  6.  {
  7.   if(document.rec.loc.options.selectedIndex = = 0)
  8.    {
  9.     alert(" hi");
  10.     return false;
  11.    }
  12.    else
  13.     return true;
  14.   }
  15.  
  16.  
  17. function validatePID(inputfield, helptext)
  18.  {
  19.   if(inputfield.value.length !=9)
  20. `  {
  21.     if(helptext != null)
  22.      helptext.innerHTML = "please enter excatly 9 digits";
  23.      return false;
  24.    }
  25.   else
  26.    {
  27.      if(helptext != null)
  28.      helptext.innerHTML = "";
  29.      return true;
  30.  
  31.   }
  32. }
  33.  
  34. </script>
  35.  
  36. </head>
  37.  
  38. <form method = "post" action="rec.asp" id="rec" name="rec">
  39. <table>
  40.  <tr>
  41.  <td>
  42.   <input id='pid' name='pid' onblur="validatePID(this,document.getElementById('pid_help'))">
  43.   <span id ="pid_help" class="help" > </span> <br> <br>
  44. </td>
  45.  
  46.  
  47. <td>
  48. <select id='loc' name='loc' onblur="validateCB()"> <span id="loc_help"> 
  49. <option value = ' ' selected > select location </option>
  50. <option value = 'abcd' selected > abcd </option>
  51. <option value = '1234' selected > 1234 </option>
  52. </td>
  53. </table>
  54.  
  55. </form>
  56. </html>
  57.  
  58.  
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....
Mar 9 '09 #1
9 2073
pronerd
392 Expert 256MB
There should not be a space between the equals signs.

Expand|Select|Wrap|Line Numbers
  1. selectedIndex = = 0

Should be

Expand|Select|Wrap|Line Numbers
  1. selectedIndex == 0
Mar 9 '09 #2
sorry...
that was a typing error...
the problem still is the same...
please correct the code..
Mar 9 '09 #3
pronerd
392 Expert 256MB
Too many errors to explain them all. Here are working versions of the functions

Expand|Select|Wrap|Line Numbers
  1.  
  2. function validateCB() {
  3.     if(document.rec.loc.options.selectedIndex == 0)   {
  4.         alert(" hi");
  5.     return false;
  6.     } else {
  7.     return true;
  8.     }
  9. }
  10.  
  11.  
  12. function validatePID(inputfield, helptext) {
  13.     if(inputfield.value.length !=9)   {
  14.     if(helptext != null) {
  15.         helptext.innerHTML = "please enter excatly 9 digits";
  16.         return false;
  17.     } else {
  18.         if(helptext != null) {
  19.             helptext.innerHTML = "";
  20.         return true;
  21.          }
  22.     }
  23.     }
  24. }
  25.  
  26.  
Mar 9 '09 #4
thank's a lot..........
now , what i want it use a funciton like validatePID inplace of validateCB on the onblur event....

have tried...but doesn't seem to work for me...
Mar 10 '09 #5
acoder
16,027 Expert Mod 8TB
What have you tried? Do you mean you want to display a message instead of an alert?
Mar 10 '09 #6
yeah...
the way it does for the PID....
Mar 10 '09 #7
acoder
16,027 Expert Mod 8TB
Show me what you've tried and I'll tell you what corrections you need to make.
Mar 10 '09 #8
Expand|Select|Wrap|Line Numbers
  1.  function validateCB() 
  2.       {
  3.      if(document.rec.loc.options.selectedIndex == 0)   
  4.     {
  5.          if (helptext != null) 
  6.         {
  7.               helptext.innerHTML = "please select atleast one value from the list";
  8.               return false;
  9.             } 
  10.          else 
  11.           {
  12.              if(helptext != null) 
  13.          {
  14.                helptext.innerHTML = "";
  15.                return true;
  16.              }
  17.            }
  18.  
  19.      }
  20.      }
  21.  
  22.  
  23.  
  24.  function validatePID(inputfield, helptext) {
  25.      if(inputfield.value.length !=9)   {
  26.      if(helptext != null) {
  27.          helptext.innerHTML = "please enter excatly 9 digits";
  28.          return false;
  29.      } else {
  30.          if(helptext != null) {
  31.              helptext.innerHTML = "";
  32.          return true;
  33.           }
  34.      }
  35.      }
  36.  }
  37.  
  38.  
this is what i am trying to achieve.........
it gives the error ' is null or not an object'...
thank's ..
Mar 10 '09 #9
acoder
16,027 Expert Mod 8TB
You need to add helptext as an argument:
Expand|Select|Wrap|Line Numbers
  1.  function validateCB(helptext)
Also, add an argument in the HTML when you call this function similar to the call for validatePID.

In the function, your brackets are not quite correct. It'd help a lot if you could align them properly:
Expand|Select|Wrap|Line Numbers
  1. if(document.rec.loc.options.selectedIndex == 0)   
  2. {
  3.     if (helptext != null) 
  4.     {
  5.         helptext.innerHTML = "please select atleast one value from the list";
  6.         return false;
  7.     }
  8. }
  9. else 
  10. {
  11.     if(helptext != null) 
  12.     {
  13.         helptext.innerHTML = "";
  14.         return true;
  15.     }
  16. }
Mar 10 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Bartosz Wegrzyn | last post by:
I use onblue event to validate fields in my form. I do this onblur="return isname()" and so so ... I have one form with 20 fields. My problem is that when the focus is for example on the...
2
by: D. Alvarado | last post by:
Hi, I'm having some trouble with the "onBlur" event in the BODY tag. Ideally, what I want to happen is that when someone leaves window A, window A executes a command. I had put <body...
4
by: Peloux | last post by:
Hi, I have written some htc in order to validate data in a form. most of htc are attached on 'onblur' event. Now, we would like to use the Enter Key to sublit form, so we use the following...
2
by: andyalean | last post by:
Hello javascript coders :( ,I am trying to add an onblur event to my code. This is where I dynamically create a textfield.I want to assign it an onblur event handler like so.How do I add a event...
5
by: Dave Hammond | last post by:
Hi All, I have a web form which performs certain actions upon moving focus away from a field. However, if the user clicks the top corner 'X' icon to close the window, the onBlur event still...
2
by: Heiko Vainsalu | last post by:
Hi Hope somebody knows how to solve this one. *The Situation* A traditional situation where HTML form inputs are checked... (if simplified then it would look something like this) <form...
1
by: suresh_nsnguys | last post by:
Hi, i am displaying google.com website inside a frame with frameset setting onblur="self.focus();". but when i am trying to enter some text in google search box,the text is not getting...
10
by: John Kotuby | last post by:
Hello all... I am working on an ASP.NET 2.0 application with VS2005 and VB. I have chosen to use popup windows in some cases because it makes the user experience better (according to all the users...
2
by: wolverine | last post by:
Hi All, In Mozilla Firefox, to onblur and onfocus event of each and every html element, the browser itself will attach a native event handler. I mean if you type,...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.