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....
9 2099 pronerd 392
Recognized Expert Contributor
There should not be a space between the equals signs.
Should be
sorry...
that was a typing error...
the problem still is the same...
please correct the code..
pronerd 392
Recognized Expert Contributor
Too many errors to explain them all. Here are working versions of the functions -
-
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;
-
}
-
}
-
}
-
}
-
-
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...
acoder 16,027
Recognized Expert Moderator MVP
What have you tried? Do you mean you want to display a message instead of an alert?
yeah...
the way it does for the PID....
acoder 16,027
Recognized Expert Moderator MVP
Show me what you've tried and I'll tell you what corrections you need to make.
-
function validateCB()
-
{
-
if(document.rec.loc.options.selectedIndex == 0)
-
{
-
if (helptext != null)
-
{
-
helptext.innerHTML = "please select atleast one value from the list";
-
return false;
-
}
-
else
-
{
-
if(helptext != null)
-
{
-
helptext.innerHTML = "";
-
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;
-
}
-
}
-
}
-
}
-
-
this is what i am trying to achieve........ .
it gives the error ' is null or not an object'...
thank's ..
acoder 16,027
Recognized Expert Moderator MVP
You need to add helptext as an argument: -
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: - if(document.rec.loc.options.selectedIndex == 0)
-
{
-
if (helptext != null)
-
{
-
helptext.innerHTML = "please select atleast one value from the list";
-
return false;
-
}
-
}
-
else
-
{
-
if(helptext != null)
-
{
-
helptext.innerHTML = "";
-
return true;
-
}
-
}
Sign in to post your reply or Sign up for a free account.
Similar topics |
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
|
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...
|
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(){
|
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;
|
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.
| |
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)">
|
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.
|
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...
|
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()'
|
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,...
|
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...
| |
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,...
|
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...
|
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...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |