Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 4th, 2004, 08:05 AM
Authorized User
 
Join Date: Feb 2004
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Default SCRIPT WORKS WITH IE BUT NOT NETSCAPE!!!

Hello,
I have a very easy authentication script that works fine... but when there are errors (like incorrect user, config file does not exist...), it only works with IE and not with NETSCAPE!!!.
It is driving me crasy!!!
Help please!!
Here is part of the code (I have simplidfied it) and I have put traces so you can see why it does not work with Netscape.

With Explorer: I get the following alerts
Entering errorConfig
error is 2
exception is EXCEPTION


With Netscape: I only get;
Entering errorConfig
 ....
WHY!!!!
<html>
<head>
<title> Authentication Engine </title>
<script language=JavaScript>
javascript:window.history.forward(1);

<!--- oculta el script para navegadores antiguos
function errorConfig()
{
alert("Entering errorConfig");
var error=document.form2.error.value;
alert("error is "+error);
    ex=document.form2.ex.value;
alert("exception is "+ex);
document.location.href="login.jsp";
}

function result()
{
 var error=document.form1.error.value;
    message=document.form1.message.value;
 alert(error+":"+message);
 document.location.href="login.jsp";
}

function page_menu()
{
 document.location.href="menu.jsp";
}

function page_login()
{
 document.location.href="login.jsp";
}

// end hiding from old browsers -->
</script>
</head>
<%@page errorPage="errorPage.jsp"%>
<%@page language="java" %>
<%@page import="java.util.*" %>
<%@page import="java.io.*" %>
<%@ page import="javax.servlet.*, javax.servlet.http.*"%>
<%@ page import="javax.servlet.http.HttpServletRequest"%>
<%
int retCode=2;
System.out.println("login.jsp retCode="+retCode);
if (retCode != 0)
{
  // Config error => Goes to login.jsp
  //-----------------------------------
%>
  <form name=form2 method="post">
   <input type=hidden name="error" value=<%=retCode%>>
   <input type=hidden name="ex" value="Exception">
  </form>
  <script language="javaScript">errorConfig();</script>
<%
}

// Read password and uid
//----------------------
System.out.println("Read uid and password");
String uid=request.getParameter("uid");
String password=request.getParameter("password");
if ((uid != null) && (!uid.equals("")) &&
    (password != null) && (!password.equals("")))
{
  String[] res={"1", "NOT AUTHENTICATED"};
  System.out.println("authenticate.jsp - aut="+res[0]);
  if (!res[0].equals("0"))
  {
    // NOt authenticated ==> Goes to login.jsp
    //-----------------------------------------
%>
    <form method="post" name=form1>
       <input type=hidden name="error" value=<%=res[0]%>>
       <input type=hidden name="message" value="<%=res[1]%>">
    </form>
    <script language="javaScript">result();</script>
<%
  }
   // Go to menu.jsp
  //----------------
%>
   <script language="javaScript">page_menu();</script>
<%
}

// Go back to login.jsp (empty uid/password)
//-----------------------------------------
%>
<script language="javaScript">page_login();</script>
</html>




 
Old October 4th, 2004, 05:00 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

This line:
javascript:window.history.forward(1);

should be, I think:

window.history.forward(1);

-Snib <><
http://www.snibworks.com
There are only two stupid questions: the one you don't ask, and the one you ask more than once ;)
 
Old October 5th, 2004, 02:52 AM
Authorized User
 
Join Date: Feb 2004
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, I changed it just in case but the problem is still there. I enter an incorrect username:
   - Explorer: goes to result() and fires the alert then goes to login.jsp
    - Netscape: goes to result() and does not fire the alert, then goes to login.jsp. It is as if the error or the message variables were not recognized by Netscape (putting an alert just after the error variable is not fired).


 
Old October 5th, 2004, 12:22 PM
Registered User
 
Join Date: Oct 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Try using "Get" as your form method.

The "Get" method sends the input as an environment variable, whereas "Postt" sends it as a standard input string. Since your value is a JSP variable you may need to use "Get" rather than "Post".

I am not sure why this would work in IE and not Netscape, however.

 
Old October 5th, 2004, 03:08 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Ulrich I believe that is irrelevant and incorrect. JSP can retrieve POST values.

elisabeth,

What does the pop-up in Explorer say? I bet it's only one word. You need to assign HTML attribute values surrounded in quotes, as it complies with the standards and should solve your problem.

So this...

<input type=hidden name="error" value=<%=res[0]%>>

...should be...

<input type='hidden' name='error' value='<%=res[0]%>'/>

Try it :-)

-Snib <><
http://www.snibworks.com
There are only two stupid questions: the one you don't ask, and the one you ask more than once ;)
 
Old October 6th, 2004, 03:25 AM
Authorized User
 
Join Date: Feb 2004
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I finally found what the problem was. ..... the <body> tag was missing! Explorer did not care about it but Netscape could not recognize the forms!!!!

Problem solved. Thank you all for your inputs.







Similar Threads
Thread Thread Starter Forum Replies Last Post
script not working in mozilla, but works in IE grobar Javascript 1 April 9th, 2008 03:51 AM
script not working in mozilla but works in IE grobar Javascript How-To 0 May 26th, 2005 06:19 PM
Login.aspx works in netscape, but not IE cohansh1 BOOK: ASP.NET Website Programming Problem-Design-Solution 3 February 23rd, 2005 09:05 AM
Webuivalidation script doesnt work in netscape olambe BOOK: ASP.NET Website Programming Problem-Design-Solution 2 July 29th, 2004 07:30 AM
code works in IE but not netscape Toka1 Javascript How-To 2 November 27th, 2003 05:35 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.