473,807 Members | 2,763 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

list and onblur event..

52 New Member
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 2099
pronerd
392 Recognized Expert Contributor
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
aashishn86
52 New Member
sorry...
that was a typing error...
the problem still is the same...
please correct the code..
Mar 9 '09 #3
pronerd
392 Recognized Expert Contributor
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
aashishn86
52 New Member
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 Recognized Expert Moderator MVP
What have you tried? Do you mean you want to display a message instead of an alert?
Mar 10 '09 #6
aashishn86
52 New Member
yeah...
the way it does for the PID....
Mar 10 '09 #7
acoder
16,027 Recognized Expert Moderator MVP
Show me what you've tried and I'll tell you what corrections you need to make.
Mar 10 '09 #8
aashishn86
52 New Member
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 Recognized Expert Moderator MVP
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
13079
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 first field of my form the "name" field and I click somewher or press tab than I loose focus and my isname() function is executed. Everything is fine but the focus was change for next field
2
3734
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 onBlur="savePage();"> I have a couple of problems. On IE 6 (win2000), whenever I put the cursor focus on a textfield within window A, the "savePage" function is invoked. And on Mozilla Filefox 0.9.1, the event never launches even when I leave the...
4
7607
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 code : ----------- <SCRIPT> function touche_EnterKeyPress(){
2
11464
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 to a newly created option text field.Thanks :D for( ;k < holdHalfHours; k++ ){ timeLog.appendChild(br); l = k +1;
5
7601
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 fires. If, for example, the onBlur event was an alert() popup: when the user clicks the close window icon, the window closes and then the alert pops up. Clearly, if the user closed the window, there is no point to performing the onBlur event.
2
5697
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 onSubmit="return checkWholeForm(this)">
1
2442
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 displayed. when i remove this 'onblur' event handler from frameset.the text is getting displayed in search box. i don't want to remove the 'onblur' event handler and i want keyboard interaction with frames.is there any way to achieve it.
10
2464
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 I have polled who will be using this app). In an attempt to keep the popup from disappearing behind the calling window, I am adding the onblur="FocusMe():" event to the Body tag of the popup. I really want onblur to react to any click outside...
2
4711
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, 'javascript:alert(window.blur)' in the address bar of Firefox browser, you can see a 'function ....' . That is a Firefox browser defined handler. Now assume that web developer also attach event handlers to 'onblur' events eg: 'window.blur=f3()'
0
9599
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10371
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10374
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10111
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7650
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6877
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5546
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5684
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3853
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.