Hi all,
I have a web form that is generated on the fly. I need to insert some javascript into the form to do validation on the contents of each text box when the text box loses focus. here is what I have - <SCRIPT language=JavaScript>
-
<!-- Begin
-
function filterNum(obj) {
-
re = /^$|!|$|<|>|"|'|%|,|&|%|;/g;
-
// remove spcial charcters
-
obj.value = obj.value.replace(re, "");
-
}
-
// End -->
-
-
var oldonload = window.onload
-
if (typeof window.onload != 'function') {
-
window.onload = mtc1006(document.ctl01);
-
} else {
-
window.onload = function() {
-
if (oldonload) {
-
oldonload();
-
}
-
mtc1006(document.ctl01);
-
};
-
}
-
-
function mtc1006(obj)
-
{
-
var children = obj.childNodes;
-
for (var i=0; i<children.length; i++) {
-
children[i].onBlur = filterNum(children[i]);
-
mtc1006(children[i]);
-
}
-
}
-
</SCRIPT>
-
However, this doesn't work. Am I using the wrong syntax when setting the onBlur?
7 2763 gits 5,390
Recognized Expert Moderator Expert
hi ...
you need to 'closure' the incremented values: -
for (var i = 0; i < children.length; i++) {
-
children[i].onBlur = function(node) {
-
return filterNum(node);
-
}(children[i]);
-
-
mtc1006(children[i]);
-
}
-
kind regards
sorry to be a pest, here is the code i have now: -
<SCRIPT language=JavaScript>
-
<!-- Begin
-
function filterNum(obj) {
-
re = /^$|!|$|<|>|"|'|%|,|&|%|;/g;
-
// remove spcial charcters
-
obj.value = obj.value.replace(re, "");
-
}
-
// End -->
-
-
var oldonload = window.onload
-
if (typeof window.onload != 'function') {
-
window.onload = mtc1006(document.ctl01);
-
} else {
-
window.onload = function() {
-
if (oldonload) {
-
oldonload();
-
}
-
mtc1006(document.ctl01);
-
};
-
}
-
-
function mtc1006(obj)
-
{
-
var children = obj.childNodes;
-
for (var i=0; i<children.length; i++) {
-
children[i].onBlur = function(node) {
-
return filterNum(node);
-
}(children[i]);
-
-
mtc1006(children[i]);
-
}
-
}
-
</SCRIPT>
this still does not work. Do I need to change the way filterNum works? should that just take the string value to validate, and handle the setting of the textbox.value in the onBlur function? I'm not sure how I would do that. Any help would be greatly appreciated.
gits 5,390
Recognized Expert Moderator Expert
When I run it in Firefox it does not generate any errors. However, in IE I get a "not implemented" error for the line :
window.onload = mtc1006(documen t.forms['ctl01']);
here is the full form I am testing, i added an additional condition to the loop to only adjust the onBlur property for "Input" tags: - <HTML><BODY>
-
-
<form name="ctl01" method="post" id="ctl01">
-
<table class="text" border="0" cellpadding="3" cellspacing="1" width="600">
-
<tbody>
-
<tr bgcolor="#eeeeee">
-
<td colspan="2" width="760"><strong><font face="Arial, Helvetica, sans-serif"><span class="style1 star style5">*</span><span class="style5"> </span></font></strong><strong><font face="Arial, Helvetica, sans-serif"><span class="style5"><font size="-2">denotes required field</font></span></font></strong></td></tr>
-
-
<tr bgcolor="#dddddd">
-
<td><strong><font face="Arial, Helvetica, sans-serif">* First Name</font></strong></td>
-
<td nowrap="nowrap"><font face="Arial, Helvetica, sans-serif"><table cellspacing="0" cellpadding="0" border="0" style="border-style:None;border-collapse:collapse;">
-
<tr valign="top">
-
<td align="left"><input name="FirstName" type="text" id="FirstName" IsRequired="True" style="" /></td>
-
</tr>
-
</table></font></td></tr>
-
<tr bgcolor="#eeeeee">
-
<td><strong><font face="Arial, Helvetica, sans-serif"><span class="style5">* Last Name</span></font></strong></td>
-
<td><font face="Arial, Helvetica, sans-serif"><table cellspacing="0" cellpadding="0" border="0" style="border-style:None;border-collapse:collapse;">
-
<tr valign="top">
-
-
<td align="left"><input name="LastName" type="text" id="LastName" IsRequired="True" style="" /></td>
-
</tr>
-
</table></font></td></tr>
-
<tr bgcolor="#dddddd">
-
<td><strong><font face="Arial, Helvetica, sans-serif"><span class="style1 star style5">Email</span></font></strong></td>
-
<td><font face="Arial, Helvetica, sans-serif"></font><br><table cellspacing="0" cellpadding="0" border="0" style="border-style:None;border-collapse:collapse;">
-
<tr valign="top">
-
<td align="left"><input name="EmailAddress" type="text" id="EmailAddress" IsRequired="False" style="" /></td>
-
</tr>
-
</table> </td></tr>
-
-
<tr bgcolor="#eeeeee">
-
<td><strong><font face="Arial, Helvetica, sans-serif"><span class="style1 star style5">Company</span></font></strong></td>
-
<td><font face="Arial, Helvetica, sans-serif"><table cellspacing="0" cellpadding="0" border="0" style="border-style:None;border-collapse:collapse;">
-
<tr valign="top">
-
<td align="left"><input name="Company" type="text" id="Company" IsRequired="False" style="" /></td>
-
</tr>
-
</table></font></td></tr>
-
<tr bgcolor="#eeeeee">
-
<td><strong><font face="Arial, Helvetica, sans-serif"><span class="style1 star style5">Phone</span></font></strong></td>
-
<td><table cellspacing="0" cellpadding="0" border="0" style="border-style:None;border-collapse:collapse;">
-
<tr valign="top">
-
<td align="left"><input name="WorkPhone" type="text" id="WorkPhone" IsRequired="False" style="" /></td>
-
</tr>
-
</table> <br></td></tr>
-
<tr bgcolor="#eeeeee">
-
<td><strong><font face="Arial, Helvetica, sans-serif"><span class="style1 star style5">Integer</span></font></strong></td>
-
-
<td><table cellspacing="0" cellpadding="0" border="0" style="border-style:None;border-collapse:collapse;">
-
<tr valign="middle">
-
<td align="right"><span style="">inttest: </span></td><td align="left"><input name="inttest__c" type="text" id="inttest__c" IsRequired="False" /></td>
-
</tr>
-
</table><br></td></tr>
-
<tr>
-
<td colspan="2"> <input type="submit" name="mtcSubmit" value="Submit" id="mtcSubmit" style="" /> </td></tr>
-
<tr>
-
<td colspan="2"> </td></tr></tbody></table>
-
</form>
-
<script type="text/javascript">
-
-
var oldonload = window.onload
-
if (typeof window.onload != 'function') {
-
window.onload = mtc1006(document.forms['ctl01']);
-
} else {
-
window.onload = function() {
-
if (oldonload) {
-
oldonload();
-
}
-
mtc1006(document.forms['ctl01']);
-
};
-
}
-
-
function mtc1006(obj)
-
{
-
var children = obj.childNodes;
-
for (var i=0; i<children.length; i++) {
-
if (children[i].tagName == 'INPUT') {
-
children[i].onBlur = function(node) {
-
return filterNum(node);
-
}(children[i]);
-
}
-
-
mtc1006(children[i]);
-
}
-
}
-
-
function filterNum(obj) {
-
re = /^$|!|$|<|>|"|'|%|,|&|%|;/g;
-
// remove spcial charcters
-
obj.value = obj.value.replace(re, "");
-
}
-
</script>
-
</BODY></HTML>
gits 5,390
Recognized Expert Moderator Expert
aaargh ... write the onBlur as onblur please ... is the handler-function called then?
unfortunately not, I also tried children[i].onblur = new function(node)
that also did not work. :(
gits 5,390
Recognized Expert Moderator Expert
damned ... its too late today :) ... the following lines will do the job: - children[i].onblur = function(node) {
-
return function() { filterNum(node); };
-
}(children[i]);
-
kind regards
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Andrew Thompson |
last post by:
Is it possible to set the onBlur of
a link or other focusable element
programmatically?
A search of the archive showed plenty of
examples of setting the onBlur() for each
link or form element when it was defined,
but I am after something that can iterate
all links in the page and add a common
onBlur functionality to every one.
|
by: Robert Oschler |
last post by:
I have a textarea element that I have created an onblur() handler for.
In the onblur() handler, I check to make sure that they have saved the
contents of the edit box, before leaving it.
If they have not saved the contents, when they exit the edit box, I put up
an alert telling them to perform the save.
My handler (note: the editBox variable was properly assigned a reference to
the desired HTML textarea element earlier):
|
by: ofirpicazo |
last post by:
Hi, my problem is that IE doesn't seem to do what it's supposed to, so
I hope u guys can give me a hand.
The code below is supposed to make text editable whenever it's clicked,
and it works, the problem is that IE doesn't set the onClick attribute
back to what I tell it to, at least it doesn't do anything if you click
on the text again, as opposed to what Firefox does, FF works!.
I put an alert on the onBlur event to see if IE sets the...
|
by: Dixie |
last post by:
Can I set the Format property in a date/time field in code?
Can I set the Input Mask in a date/time field in code?
Can I set the Format of a Yes/No field to Checkbox in code?
I am working on a remote update of tables and fields and can't find enough
information on these things.
Also, how do you index a field in code?
|
by: Jeffrey |
last post by:
Hello
I have several textboxes in a datagrid footer. When the user inputs
something first textbox, the values of the other textboxes are updated.
Basically I want the "onBlur" functionality of javascript here, but using
codebehind.
Why I don't want to use javascript for this is because I have to connect to
my database and all the users' browsers have to be configured to allow
"access to data source across domain" ( which doesn't seem...
| |
by: James Cooke |
last post by:
I want to set body attributes programmatically, from the module file:
I can go into the .aspx file and say <body onload="myFunc()"> but I don't
want to.
Like you do with a textbox control:
txtCustomer.Attributes("onblur") = "myFunc()"
I would like to do the same with the <body> tag.
|
by: neil S via DotNetMonster.com |
last post by:
I have a custom control with a textbox and dropdown list. The dropdown
list is hidden and acts as a data source for the textbox. When the user
enters text in the textbox, an onKeyup event is fired and retrieves the
first value from the dropdown list equal to that entered, and fills the
text box. Essentially, the two together are acting as a type
ahead/autocomplete thingy. All this works fine. Here's my problem: I
wanted to expose the...
|
by: RKT |
last post by:
I have a DataGridView bound to an MS Access table. This is a single-
user application. When the User is adding or editing a row, the User
may click on a Control elsewhere. That Control has context which I use
to programmatically set *other* r/o cell values for the currently
selected grid row. So, after that click on another control, and
stuffing the related cell values, I want to seamlessly allow the user
to resume editing/adding that row...
|
by: rubenhan |
last post by:
Hey, guys.
My basic idea is this. When I write "1" in the pre-existing text field and onblur, I want to add a new field with a set of attributes, which turned out to be the same as the pre existing text field. (I don't want to use clonenode because of the compatibility issue)
So I want that new text field to behave like the old text field. However, the new text field does not create another text field when I write "1" into it and onblur...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |