473,703 Members | 3,129 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Netscape getElementById Issue



I am sure this is a simple issue, but being a beginner I am struggling.
In the following js function I am attempting to make sure no numbers are
within "name" controls. I want to pass the text value of the HTML
control and the control name into the function:
function CheckForNumbers (strString, strField) {
var result = true;
var validNums = "0123456789 ";
var alertHeader = "The following error(s) occured:\n\n";
var alertErr = "";
for (x=0; x < strString.lengt h; x++) {
if (validNums.inde xOf(strString.c harAt(x)) != -1) {
alertErr += "->This Field Cannot Contain Numbers\n";
break;
}
}
if (alertErr) {
result = false;
document.getEle mentById(strFie ld).focus();
alert (alertHeader + alertErr);
}

return result;
}

I don't know if this is the smartest way to do this, just the way I
thought of. The bottom line is I would like the code to check the value
to see if there is a number, and set focus back to the offending control
for the user to correct the problem. This works without a problem in
Internet Explorer, version 6 (latest Service packs, hot fixes, etc), but
in Netscape, version 7.2, I am getting the following error in the
JavaScript console:
Error: document.getEle mentById(strFie ld) has no properties
Source File: http://127.0.0.1:8100/TestJscript.jsp
Line: 104

Sorry this is so long, but I wanted to be as complete as possible and I
appreciate any help.
Ron
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #1
3 2165
Lee
Ron M said:

I am sure this is a simple issue, but being a beginner I am struggling.
In the following js function I am attempting to make sure no numbers are
within "name" controls. I want to pass the text value of the HTML
control and the control name into the function:
function CheckForNumbers (strString, strField) {
var result = true;
var validNums = "0123456789 ";
var alertHeader = "The following error(s) occured:\n\n";
var alertErr = "";
for (x=0; x < strString.lengt h; x++) {
if (validNums.inde xOf(strString.c harAt(x)) != -1) {
alertErr += "->This Field Cannot Contain Numbers\n";
break;
}
}
if (alertErr) {
result = false;
document.getEle mentById(strFie ld).focus();
alert (alertHeader + alertErr);
}

return result;
}

I don't know if this is the smartest way to do this, just the way I
thought of. The bottom line is I would like the code to check the value
to see if there is a number, and set focus back to the offending control
for the user to correct the problem. This works without a problem in
Internet Explorer, version 6 (latest Service packs, hot fixes, etc), but
in Netscape, version 7.2, I am getting the following error in the
JavaScript console:
Error: document.getEle mentById(strFie ld) has no properties
Source File: http://127.0.0.1:8100/TestJscript.jsp
Line: 104

Sorry this is so long, but I wanted to be as complete as possible and I
appreciate any help.


It works in IE because IE considers the "name" field to be sorta
kinda the same as the "id" field, whereas Netscape was written by
reasonable people who insist that you actually pass an id value to
getElementById( ).

It's almost always better to pass a reference to an control than
to pass the name. That way you avoid having to look it up later,
and the value doesn't have to be passed separately:
function CheckForNumbers (field) {
var result=true;
if (-1 != field.value.sea rch(/\d/) ) {
// The search for a digit in the value was sucessful
result = false;
alert ("This Field Cannot Contain Numbers");
field.focus();
}
return result;
}

<form onsubmit="retur n CheckForNumbers (this.firstName )">
<input name="firstName "><br>
<input type="submit">
</form>

Jul 23 '05 #2
I will try that, thank you for the quick response. Ron

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #3
JRS: In article <42********@127 .0.0.1>, dated Tue, 22 Feb 2005
16:15:11, seen in news:comp.lang. javascript, Ron M
<an*******@devd ex.com> posted :
I am sure this is a simple issue, but being a beginner I am struggling.
In the following js function I am attempting to make sure no numbers are
within "name" controls.


But what, for you, is a "number"? There are two numbers in the name of
one who had a narrow escape almost 400 years ago, James I & VI. Do you
perhaps mean "decimal digits"? If you do, then say so.
You can use var Bad = /\d/.test(field.val ue) for that.

However, what you ask for is probably not what you want; it will allow
an empty string, or one containing any characters other than the ten
digits, probably including whatever character \uABCD may be.

Assuming that "name" is something like a personal or geographical name,
and that the working language is a dialect of English, there is a finite
set of characters that one needs to allow in name fields ;
a-z A-Z space ' ! - at least.

So var OK = /^[a-z '!-]+$/i.test(field.va lue) though
you may (wrongly) consider just one character to be too short.

For real names of Continental origin, various accented characters should
be allowed.

The test should be done, however, after trimming the field of leading or
trailing spaces - newsgroup FAQ 4.16.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
3686
by: Scott | last post by:
Hello All, I've been reading all of the various issues with Iframes in netscape. I have tried all of the various fixes posted, and have even implemented both an iframe and ilayer. My problem is that no matter which i use, i can access the src before and after i change it, but the page never displays. in IE6 it works no matter how i access it. here is the code that is changing it: function InternalNav(sPage) {
1
2880
by: Catherine Lynn Smith | last post by:
OK, I know this issue has been beat to death, but I have tested my script in Netscape 7.1 and it does seem to be getting the calculated values it needs to create placement coordinates, and every example I can find that 'works' in my netscape browser "appears" to use the same style references to the various div objects that I am trying to use. Yet even though I have verified the script is stepping through the doResize subroutine, and the...
3
1231
by: Jeannie | last post by:
Can anyone help me adjust this code so that it works in Netscape 4.x? I have am developing a website for a restaurant and the menu page has menus for lunch and dinner. Two images work as tabs, so that when you click on the lunch menu, only that menu is visible, and likewise, when you click on the dinner tab, only the dinner menu is visible. This code works like a charm on IE 5.5, but I don't know how to get a workable solution on...
11
1517
by: Jon | last post by:
Hi, I have a function that uses the following line: var level = document.getElementById( id); I also know the name of the element I am looking for. In Netscape Communicator 4.7, however, this doesn't work... What can I do to get the same element in this browser? Thanks!
4
5476
by: lawrence | last post by:
Can anyone tell me why this code works in Netscape 7.1 but not in IE??? <SCRIPT type='text/javascript'> function makeVisible(nameOfDiv) { document.getElementById(nameOfDiv).style.visibility='visible'; document.getElementById(nameOfDiv).style.height='auto'; if (nameOfDiv != 'weblogs')
5
2177
by: Zambien | last post by:
Hi all, Here's my problem. I have tables that are using the menu/submenu idea for hiding rows. This works fine in IE (of course) and does show/hide correctly in netscape, but as soon as the shown method is called, the table gets skewed and the presentation of the data on the page goes horribly wrong. I don't think this is a table issue as I have spent alot of time staring at this code. Here is the html...
26
2191
by: Roger Desparois | last post by:
Hi, I need help : I found the simplest and most precise way to open and close submenu layers. it works perfectly with IE, but for some odd reason NS won't recognize it. Can anyone tell me why ? And is there a way around the problem ?
5
1659
by: zaw | last post by:
Hi I am working on implementing this script to shopping cart. Basically, it copies fill the shipping address from billing automatically. I believe one or more syntax is not netscape compatible. Can anyone point out which one it is and how to make it both netscape and MS browser compatible? I hope if I can make the script compatible for those two at extreme, it will probably work with most browser out there. As you would notice, this form...
2
5364
by: AndrewW | last post by:
Hi I have an application that draws a selection rectangle over a map image. I can get it to work fine in IE and Opera, but not Firefox/Netscape. I've thrown the following small example together to illustrate the problem - the problem being that FF/NE initially draw my rectangle before the icon changes immediately to the black no-entry icon. Then, when I let go of the mouse, the rectangle continues drawing, but it
0
8749
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9243
Oralloy
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...
0
9109
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...
0
8956
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...
0
7853
agi2029
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...
1
6585
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
5922
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
4420
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...
1
3113
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 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.