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

Strange problem with field verification in IE

I am having a strange problem with field verification in a form. The
JavaScript below works just fine in Firefox but in IE. "license" is a
pull-down list and "requiredDiscount" is a text field. When license is
"Freeware" and requiredDiscount is "N/A", in IE (but not Firefox) you
get the message "For trialware you must enter a valid discount". It
seems that in IE "this", the form, is not set. I also tried using
"document.form" instead of "this" but then you can have
requiredDiscount as "N/A" when license is not "Freeware". Can anyone
explain what is wrong here?

-------------------

<html><head>
<script language="javascript">
<!--
function submitIt(form){
var licChoice = form.license.selectedIndex
var sDiscount = form.requiredDiscount.value
if ((form.license.options[licChoice].value == "Freeware") &&
(sDiscount != "N/A")){
alert("For freeware you must enter a discount of N/A")
return false
}
sDiscount = sDiscount.toUpperCase()
if ((sDiscount == "N/A") && (form.license.options[licChoice].value
!= "Freeware")){
alert("For trialware you must enter a valid discount")
return false
}
return true
}
-->
</script>

</head>

<body>
<form onSubmit="return submitIt(this);" action="list.cgi"
name="submitForm" method="post"
enctype="application/x-www-form-urlencoded">
[...]
Non-profit Discount: (e.g.: 10% - enter N/A for freeware)<br>
<textarea name="requiredDiscount" rows="3"
cols="61">N/A</textarea><br>
Software license:<br>
<select name="license"><option
selected="selected">Time-limited trial</option><option>Feature-limited
demo</option><option>Commercial</option><option>Freeware</option></select>
[...]

_______
Trade your DVDs, movies and CDs for Free!
http://www.dvdtrades.net
Aug 22 '05 #1
1 1472
Mike the Canadian wrote:
I am having a strange problem with field verification in a form. The
JavaScript below works just fine in Firefox but in IE. "license" is a
pull-down list and "requiredDiscount" is a text field. When license is
"Freeware" and requiredDiscount is "N/A", in IE (but not Firefox) you
get the message "For trialware you must enter a valid discount". It
seems that in IE "this", the form, is not set. I also tried using
"document.form" instead of "this" but then you can have
requiredDiscount as "N/A" when license is not "Freeware". Can anyone
explain what is wrong here?

-------------------

<html><head>
<script language="javascript">
The language attribute is depreciated, type is required.

<script type="text/javascript">
<!--
HTML comments inside script elements are unnecessary and potentially
harmful if your page is later converted to XHTML without removing the
comment markers. Just don't use them.
function submitIt(form){
var licChoice = form.license.selectedIndex
var sDiscount = form.requiredDiscount.value
if ((form.license.options[licChoice].value == "Freeware") &&
Here is your problem. The value of the option should be the content
(text) if there is no value attribute, however IE doesn't follow the
spec. So use the option's text:

if ((form.license.options[licChoice].text == "Freeware") &&

That will work in all compliant browsers.
(sDiscount != "N/A")){
alert("For freeware you must enter a discount of N/A")
return false
}
sDiscount = sDiscount.toUpperCase()
if ((sDiscount == "N/A") && (form.license.options[licChoice].value
Same here.

Using semi-colons to terminate lines is not strictly necessary but it is
good practice to always put them in.
!= "Freeware")){
alert("For trialware you must enter a valid discount")
return false
}
return true
}
-->
</script>

</head>

<body>
<form onSubmit="return submitIt(this);" action="list.cgi"
name="submitForm" method="post"
enctype="application/x-www-form-urlencoded">
[...]
Non-profit Discount: (e.g.: 10% - enter N/A for freeware)<br>
<textarea name="requiredDiscount" rows="3"
cols="61">N/A</textarea><br>
Software license:<br>
<select name="license"><option
selected="selected">Time-limited trial</option><option>Feature-limited
Using - selected="selected" may trip up some browsers. If your doctype
is HTML, then just the 'selected' attribute should be added with no value.
demo</option><option>Commercial</option><option>Freeware</option></select>
Properly blocking your code makes life much easier for those who would
try to help.
[...]

_______
Trade your DVDs, movies and CDs for Free!
http://www.dvdtrades.net

--
Rob
Aug 22 '05 #2

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

Similar topics

3
by: Paul Porcelli | last post by:
I have the following code(excerpt) which grabs some lines from a syslog file and adds any found in the range to an array. @lines=();@vvlines=(); $t = new Net::Telnet (Timeout => 30, Prompt =>...
8
by: gunawardana | last post by:
I have to write a program to verify text field in HTML forms. So,I hane to verify a text field with lenth 10 & maxlenth 10.The entered text should be as follows. xxxxxxxxxy where xxxxxxxxx...
1
by: Will | last post by:
(My 4 questins at end after explination) The code below was provided to me to "Popup" a window explaining what a Credit Card Verification Number is and where to find it on a card... it is used as...
7
by: Anon Email | last post by:
Hi people, I'm playing around with Bartosz Milewski's code at the moment, and I got the following strange results upon execution of the code included further below. Please be aware that I...
2
by: Will | last post by:
(My 4 questins at end after explination) The code below was provided to me to "Popup" a window explaining what a Credit Card Verification Number is and where to find it on a card... it is used as...
3
by: Bill | last post by:
I'm using the POST method to submit a simple form html page with yes/no and checkbox fields to an asp response page which stores the values in a new dim string, then uses it to build a new table...
2
by: Robbie Hatley | last post by:
I'm getting a strange warning at work when I compile any file in our product that contains a deque of a particular struct. I don't understand this warning, so I'm not sure if this is a Microsoft...
1
by: vbnewb | last post by:
Hey All, I am new to the forums. Have been reading a bit here on some very useful tips and tutorials here. I am familiar with the basics of Access (tables , queries, forms,) but am such a newb at...
5
by: MN | last post by:
Hi, I was writing a program that must dynamically allocate memory to a 2- dimensions array, initialize it to 0, then place the result of multiplication of two 1-dimension arrays as described in...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
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...
0
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...

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.