473,394 Members | 1,700 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,394 software developers and data experts.

javascript: test a specific element of a passed form

I am modifying existing javascript code where the author appears to be
passing an entire form to a javascript function called Require(). I
want to add a new test: "is @BHFOR.value = blanks". Interestingly it
works in Firefox but not IE so I suspect that the syntax is not
correct.

Is there a better way to test a specific element of the form in this
case?

Here is an extract of the code:

<script language="javascript" type="text/javascript">
function Require(obj) {
for (var i=0; i<obj.length; i++) {
// a bunch of numeric validations that work now.
}

// my addition that causes script to fail
if (obj.@BHFOR.value == " " )
{
alert("You must enter current License Number");
return false;
}
</script>
<form name="form1" action="OP1704.pgm"
onSubmit="return Require(this)">

<p>Enter Current License Number.</p>
<INPUT type="text" name="@BHFOR" size="25" maxlength="25" value="" >
</p>
<INPUT type="submit" name="submit" value=" Submit " class="btn">
</div>

</form>

Mar 18 '06 #1
3 1403
Hiya

The program logic seems ok, looks like the problem is the @ symbol at
the start of the input elements name. Try BHFOR instead of @BHFOR.

Mar 19 '06 #2
Bi*************@yahoo.com said on 19/03/2006 4:41 AM AEST:
I am modifying existing javascript code where the author appears to be
passing an entire form to a javascript function called Require(). I
want to add a new test: "is @BHFOR.value = blanks". Interestingly it
works in Firefox but not IE so I suspect that the syntax is not
correct.

Is there a better way to test a specific element of the form in this
case?

Here is an extract of the code:

<script language="javascript" type="text/javascript">
The language attribute is deprecated so remove it. Keep type.

function Require(obj) {
Function names starting with a capital letter are normally reserved for
constructors. No biggie, just a convention.

for (var i=0; i<obj.length; i++) {
// a bunch of numeric validations that work now.
}

// my addition that causes script to fail
if (obj.@BHFOR.value == " " )
The '@' symbol is your problem (see below). Use:

if (obj['@BHFOR'].value == " " )
or more formally:

if (obj.elements['@BHFOR'].value == " " )

{
alert("You must enter current License Number");
return false;
}
</script>
<form name="form1" action="OP1704.pgm"
onSubmit="return Require(this)">

<p>Enter Current License Number.</p>
<INPUT type="text" name="@BHFOR" size="25" maxlength="25" value="" >
Contrary to what you may have been told, the name attribute is CDATA so
you can put almost anything in there.

<URL:http://www.w3.org/TR/html4/interact/forms.html#adef-name-INPUT>
However, when using the name, if it starts with anything other than a
letter or contains anything other than letters and numbers, always use
square brackets and string literal to access it. i.e. don't use
formRef.@BHFOR use formRef['@BHFOR']. It's a good idea to always use
square brackets anyway.

</p>
<INPUT type="submit" name="submit" value=" Submit " class="btn">
There is no need to give the submit button a name, so don't. And
especially don't call it 'submit' as it will override the form's submit
method, causing an error (something like 'form.submit is not a
function') if you try to call it.

</div>
Closing div tag not opened. :-)

</form>


--
Rob
Mar 20 '06 #3
RobG wrote:
Bi*************@yahoo.com said on 19/03/2006 4:41 AM AEST:
[...]
<INPUT type="text" name="@BHFOR" size="25" maxlength="25" value="" >


Contrary to what you may have been told, the name attribute is CDATA [...]


The value of the `name' attribute of `input' elements is indeed
of type CDATA. Most `name' attribute values are. Not all.

<URL:http://www.w3.org/TR/html4/index/attributes.html>
</div>


Closing div tag not opened. :-)


s/tag/element/
Regards,
PointedEars
Mar 20 '06 #4

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

Similar topics

72
by: Stephen Poley | last post by:
I have quite often (as have probably many of you) come across HTML forms with irritating bits of Javascript attached. The last straw on this particular camel's back was a large form I was asked to...
2
by: John J | last post by:
Hi there I have the following code on a site that works as it should but I'd like to understand how it works (a luxury I realise :). I use it to change the colour of buttons on a menu when a...
15
by: binnyva | last post by:
Hello Everyone, I have just compleated a JavaScript tutorial and publishing the draft(or the beta version, as I like to call it) for review. This is not open to public yet. The Tutorial is...
136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
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...

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.