Connecting Tech Pros Worldwide Help | Site Map

IE and Netscape Difference: ASP/JavaScript Problem

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 23rd, 2005, 05:34 PM
JJ_377@hotmail.com
Guest
 
Posts: n/a
Default IE and Netscape Difference: ASP/JavaScript Problem

Why won't Netscape do the intended in the following? IE is able to
render this page as intended. It is is a "self-posting" ASP form with a
JavaScript validation function: if the form fails the JavaScript
validation function, then the form should not post and an alert should
be issued as indicated below.

The *first* alert in the Validate function works in NS, but the rest of
the code does not and therefore I wonder about the way I am referencing
the controls...tried to experiment with this, as can be seen in the
rem'd out code. Tried to research in my books...

Thanks for any and all! Jules

---------------------------------------------------------------------------------------------------------------
<%Option Explicit%>

<%
'This is a self-posting form: the same form is used for both
'the request and response objects

If not IsEmpty(request.Form("txtFirstName")) and _
Not IsEmpty(Request.Form("txtLastName")) then
'the form has been filled out and a brief thank you is sent
%>
<html>
<head>
<title>Thank You</title>

</head>

<body>
Thank you
<br><%=Request.Form("txtFirstName")%>&nbsp<%=Reque st.Form("txtLastName")%>
for your information.
Have a nice day!
</body>
</html>

<%Else%>
<!--Form has not been filled out, so provide it!-->

<html>
<head>
<script language="javascript">

function trim(strField){
alert("trim");
return strField.replace(/^\s+/,'').replace(/\s+$/,'')
}

function validate()
{
alert("validate");

//if(document.all.txtFirstName.value == "" ||
document.all.txtLastName.value == "")
if(trim(document.forms("frmInfo").elements("txtFir stName").value) ==
"" || trim(document.forms("frmInfo").elements("txtLastNa me").value) ==
"")
//document.swOrder.elements[0].value
//if(trim(document.frmInfo.elements[0].value == "" ||
trim(document.frmInfo.elements[1].value) == "")
{
document.frmInfo.reset();
alert("Please enter both first and last names.");
return false;
}
document.frmInfo.submit();
return true;
}
</script>
<title>Thank You</title>
</head>
<body>
Please fill out this form:
<form name="frmInfo" action="AllControls.asp" method="post">

First Name: <input type="text" name="txtFirstName"><br>
Last Name: <input type="text" name="txtLastName"><br>
<input type="Button" value="Submit User Info" onclick="validate()">
<input type="reset">



</form>
</body>
</html>
<%End if %>


  #2  
Old July 23rd, 2005, 05:34 PM
Richard Cornford
Guest
 
Posts: n/a
Default Re: IE and Netscape Difference: ASP/JavaScript Problem

JJ_377@hotmail.com wrote:
<snip>[color=blue]
> The *first* alert in the Validate function works in NS,
> but the rest of the code does not and therefore I wonder
> about the way I am referencing the controls...[/color]
<snip>

Why wonder, Netscape/Gecko browsers provide very explicit error reports
in their javascript console?

<script language="javascript">

The language attribute is deprecated and the type attribute is required
in valid HTML 4. So:-

<script type="text/javascript">

<snip>[color=blue]
> document.all.txtLastName.value == "")[/color]

Only the very latest Mozilla/Gecko browsers support - document.all - so
that does not include any Netscape releases.
[color=blue]
> if(trim(document.forms("frmInfo").[/color]

The - document.forms - collection is (W3C) specified as an object not a
function. As such its members should be referenced using bracket
notation.
[color=blue]
>elements("txtFirstName").value) ==[/color]
<snip>

The - elements - collection of form elements is (W3C) specified as an
object not a function. As such its members should be referenced using
bracket notation.

Netscape browsers will not have made it past those two errors.

Richard.


  #3  
Old July 23rd, 2005, 05:34 PM
RobG
Guest
 
Posts: n/a
Default Re: IE and Netscape Difference: ASP/JavaScript Problem

Richard Cornford wrote:[color=blue]
> JJ_377@hotmail.com wrote:[/color]
[color=blue]
> <snip>
>[color=green]
>>document.all.txtLastName.value == "")[/color]
>
>
> Only the very latest Mozilla/Gecko browsers support - document.all - so
> that does not include any Netscape releases.
>[/color]

IMO, you should say "have limited support for". An informative
discussion on Mozilla/Geko support for document.all is here:

<URL:https://bugzilla.mozilla.org/show_bug.cgi?id=248549>

Mozilla/Geko's support for document.all seems limited to the
ability to create a reference to an element and that's it.


--
Rob
  #4  
Old July 23rd, 2005, 05:34 PM
JJ_377@hotmail.com
Guest
 
Posts: n/a
Default Re: IE and Netscape Difference: ASP/JavaScript Problem

I tried the JavaScript Console before posting my initial question and
it returned no messages at all and so I posted my inquiry here. I tried
to change the <script> tag and the script still fails...if the control
references are incorrect, how do I correct them? I tried various ways
of using "bracket notation" as well before posting my first inquiry
(rem'd out code in original posting I believe) and did not get the
script to work. If this line is wrong, how is it to be changed to to
bracket notation so that it works in NS?
if(trim(document.forms("frmInfo").elements("txtFir stName").value) ==
"" || trim(document.forms("frmInfo").elements("txtLastNa me").value) ==
"")
?
Thank you.

  #5  
Old July 23rd, 2005, 05:34 PM
JJ_377@hotmail.com
Guest
 
Posts: n/a
Default Re: IE and Netscape Difference: ASP/JavaScript Problem

Got it!
if(trim(document.frmInfo.txtFirstName.value) == "" ||
trim(document.frmInfo.txtLastName.value) == "")

This works in Netscape and IE.

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.