JS isnt called by firefox but is in IE why?

This is the main parts of the page, i dont really understnad why but the button has no function, it doest even appear to attemp to call the JS at all. and i dont understand what may cause this...

<%@ page import="java.util.*;" %>

<%@ page contentType="text/html; charset=ISO-8859-5" %>

<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>

<html>

<head>

<title>Interactive Experience Database - Search</title>

<LINK REL="STYLESHEET" TYPE="text/css" HREF="style.css">

</head>

<SCRIPT LANGUAGE="JavaScript" SRC="main.js">

</SCRIPT>

<body>

<FORM name="myForm">

... the page is full of information butthis is the button:

<INPUT TYPE=BUTTON VALUE="Generate" onclick="generate()">

</form>

</body>

</html>

the js file:

function generate()

{

if(document.getElementById("EmployeeName2").selectedIndex =="0")

{

window.alert('You must select a Employee Name');

return;

}

if(document.getElementById("templates").selectedIndex =="0")

{

window.alert('You must select a Template');

return;

}

else

{

document.myForm.action="cvgeneration.jsp";

document.myForm.submit();

}

}

[2294 byte] By [h1400046a] at [2007-11-26 21:36:38]
# 1
Try moving your <script src="main.js"></script>Into the <head></head> section of your page.
profluxa at 2007-7-10 3:18:10 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
that makes no difference
h1400046a at 2007-7-10 3:18:10 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
Can you post your the html for your entire form instead of just the snippet?
profluxa at 2007-7-10 3:18:10 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
i have another button on the page that submits the page does this effect it?<INPUT TYPE=SUBMIT VALUE="Search">
h1400046a at 2007-7-10 3:18:10 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

[nobr]<%@ page import="java.util.*;" %>

<%@ page contentType="text/html; charset=ISO-8859-5" %>

<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>

<html>

<head>

<title>Interactive Experience Database - Search</title>

<LINK REL="STYLESHEET" TYPE="text/css" HREF="style.css">

<SCRIPT LANGUAGE="JavaScript" SRC="main.js">

</SCRIPT>

</head>

<%

String ename = request.getParameter( "EmployeeName");

session.setAttribute( "ename", ename);

String sname = request.getParameter( "SkillName" );

session.setAttribute( "sname", sname );

String yexp = request.getParameter ("yearsExp");

if (yexp != null)

{

if (yexp =="")

{

session.setAttribute( "yexp", 0);

}

else

{

boolean check = true;

for(int i=0; check && (i<yexp.length()); i++)

{

check = Character.isDigit(yexp.charAt(i));

}

if(!check)

{

session.setAttribute( "yexp", 0);

}

else

{

double yearsexp = Double.parseDouble(request.getParameter("yearsExp"));

session.setAttribute( "yexp", yearsexp);

}

}

}

else

{

session.setAttribute( "yexp", 0);

}

%>

<body>

<FORM name="myForm">

<table>

<tr>

<td width=10%>

<img src="http://localhost:8080/Experience/logo.gif" alt="Company">

</td>

</tr>

</table>

<h2> Main Page </h2>

<A href="http://localhost:8080/Experience/help.jsp">Help</A>

<br>

<A href="http://localhost:8080/Experience/Updates/update.jsp">Update</A>

<br> </br>

<table class="width">

<tr border-left-width:1px; class="heading">

<td >

<div id="largetableheader">

<font>

<b>

Reports Generation Tool

</b>

</font>

<div>

</td>

<td class="borderright">

</td>

<td width=10%>

</td>

<td>

<div id="largetableheader">

<font>

<b>

CV Generation Tool

</b>

</font>

</div>

</td>

<td>

</td>

<td>

</td>

</tr>

<tr>

<td>

</td>

<td class="borderright">

</td>

</tr>

<tr>

<td>

Employee Name:

</td>

<td class="borderright">

<jsp:useBean id="employee" class="com.Database.Employee" scope="page">

</jsp:useBean>

<select name="EmployeeName">

<option> Please Select... </option>

<c:forEach var="emp" items="${employee.employees}">

<c:choose>

<c:when test="${emp.ename == sessionScope.ename }">

<option selected="selected" name="<c:out value="${emp.forename}"/> <c:out value="${emp.surname}"/>">

<c:out value="${emp.forename}"/> <c:out value="${emp.surname}"/>

</option>

</c:when>

<c:otherwise>

<option name="<c:out value="${emp.forename}"/> <c:out value="${emp.surname}"/>">

<c:out value="${emp.forename}"/> <c:out value="${emp.surname}"/>

</option>

</c:otherwise>

</c:choose>

</c:forEach>

</select>

</td>

<td>

</td>

<td>

Employee Name:

</td>

<td >

<select name="EmployeeName2">

<option> Please Select... </option>

<c:forEach var="emp" items="${employee.employees}">

<option name="<c:out value="${emp.forename}"/> <c:out value="${emp.surname}"/>">

<c:out value="${emp.forename}"/> <c:out value="${emp.surname}"/>

</option>

</c:forEach>

</select>

</td>

<td>

</td>

</tr>

<tr>

<td>

Skill Name:

</td>

<td class="borderright">

<jsp:useBean id="skill" class="com.Database.Skill" scope="page">

</jsp:useBean>

<select name="SkillName">

<option> Please Select... </option>

<c:forEach var="s" items="${skill.skills}">

<c:choose>

<c:when test="${s.skillname == sessionScope.sname }">

<option selected="selected" name="<c:out value="${s.skillname}"/> ">

<c:out value="${s.skillname}"/>

</option>

</c:when>

<c:otherwise>

<option name="<c:out value="${s.skillname}"/> ">

<c:out value="${s.skillname}"/>

</option>

</c:otherwise>

</c:choose>

</c:forEach>

</select>

</td>

<td >

</td>

<td>

Template:

</td>

<td>

<select name="templates">

<option> Please Select... </option>

<option>Standard Resume</option>

<option>Professional Resume</option>

<option>Fully Technical Resume</option>

<option>Skills Resume</option>

</select>

</td>

<td>

</td>

</tr>

<tr>

<td>

Years Experience:

</td>

<td class="borderright">

<input type="text" name="yearsExp" value = "<%= session.getAttribute( "yexp" ) %>"/>

</td>

<td >

</td>

<td>

Output To:

</td>

<td ALIGN = LEFT>

<input type="radio" name="outputtype" value="Browser" checked="checked">Browser<br>

<input type="radio" name="outputtype" value="PDF"/>PDF<br>

</td>

</tr>

<tr>

<td>

</td>

<td class="borderright">

<INPUT TYPE=SUBMIT VALUE="Search">

</td>

<td>

</td>

<td>

</td>

<td>

<INPUT TYPE=button VALUE="Generate" onclick="generate()">

</td>

<td>

</td>

</tr>

</table>

<br> </br>

<table class="heading">

<tr>

<td>

<font>

<b> Report: Employee Skill Details: </b>

</font>

</td>

<tr>

</table>

<br> </br>

<jsp:useBean id="empskill" class="com.Database.EmployeeSkill" scope="page">

<jsp:setProperty name="empskill" property="ename" value="<%= session.getAttribute( "ename" ) %>"/>

<jsp:setProperty name="empskill" property="skillname" value="<%= session.getAttribute( "sname" ) %>"/>

<jsp:setProperty name="empskill" property="yearsexperience" value="<%= session.getAttribute( "yexp" ) %>"/>

</jsp:useBean>

<div id="report">

<table>

<tr class="reportheading">

<td>

<b>Employee Name</b>

</td>

<td>

<b>Skill Name</b>

</td>

<td>

<b>Skill Level</b>

</td>

<td>

<b>Years Experience</b>

</td>

</tr>

<c:forEach var="empskill" items="${empskill.report}">

<tr>

<td>

<c:out value="${empskill.ename}"/>

</td>

<td>

<c:out value="${empskill.skillname}"/>

</td>

<td>

<c:out value="${empskill.skilllevel}"/>

</td>

<td>

<c:out value="${empskill.yearsexperience}"/>

</td>

</tr>

</c:forEach>

</table>

</div>

</form>

</body>

</html>

Message was edited by:

h1400046[/nobr]

h1400046a at 2007-7-10 3:18:10 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
Rather than the JSP can you post the HTML that gets generated? Make the request from your browser, then view source and post the generated html? Thanks.
profluxa at 2007-7-10 3:18:10 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7

Actually... Before you do that, change your form elements and set the id attribute of Employee2 and templates as well as the name attribute.

for example:

<select id="Employee2" name="Employee2">

Problem may be that in the js you're calling getElementById, but haven't set the Id, only the name. If you don't need the name, you can leave it off.

profluxa at 2007-7-10 3:18:10 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8
i changed it and by doing that it works!! thanksMessage was edited by: h1400046
h1400046a at 2007-7-10 3:18:10 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 9
i do have the same problem with a number of other pages, is there a list of these sort of things anywere?like says you need ids for this that and the other. ?
h1400046a at 2007-7-10 3:18:10 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 10
thanksMessage was edited by: h1400046
h1400046a at 2007-7-10 3:18:10 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 11

You're probably going to run into that same problem anywhere you use the getElementById() function, but don't specify the id attribute of the element in your html/jsp. You can add the id attribute to any html tag, so just be sure that when you want to access some feature of that element through JS, you set that id attribute and you should be okay.

Glad to hear you've got it working!

Chris

profluxa at 2007-7-10 3:18:10 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 12

thanks but i have js like this:

if (chkNumeric(document.getElementById(i+"compphonenumber").value) == false)

{

alert("The phone number contains one or more non numeric values");

return;

}

and input fields like this:

<input type="text" id="<% out.print(count); %>compphonenumber" name="<% out.print(count); %>compphonenumber" value="<c:out value="${phonenumber}"/>">

can you see why this doesnt work?

Message was edited by:

h1400046

h1400046a at 2007-7-10 3:18:10 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 13

I'm not 100% certain, if this doesn't work take a look at the generated html that your jsp produces, and make sure that the value in the id attribute is what you expect. I suspect that your problem might be fixed by switching your syntax to:

<input type="text" id="<% out.print(count+"compphonenumber"); %>"

Give that a try and see... Otherwise, you've got to dig into some debugging from both the java and js sides. You'll know if the java is working like you expect just by checking the generated html and seeing if the id attribute is set correctly. The js is a bit trickier, you might want to try putting an alert() statement before your if-statement:

alert(i+"compphonenumber");

if the value in the alert is not the same as the value in your ID attribute on the html form, you know you've got to make code changes to resolve the difference.

Let me know if you get it working!

Chris

profluxa at 2007-7-10 3:18:11 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 14
Thanks so much it now works! Your a genious!
h1400046a at 2007-7-10 3:18:11 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...