Sunmit Girme
Sunmit Girme

Reputation: 559

JavaScript works on FireFox but not on Chrome or IE

Following is my code where I create a div with a adrop-down box on my page and I want an onClick event on the elements in the select :

$("div.projectTeamTools").html('Organize by Project Teams: <select id="projectTeams"><c:forEach var="projectTeam" items="${userProjectTeams}"><option value="${projectTeam.projectId}" onClick="javascript:onTeamSelect(this.value)">${projectTeam.projectName}</option></c:forEach></select>');

function onTeamSelect(teamId){
        alert(teamId +" Selected");
}

The code works fine on Firefox, but not on IE or Chrome. Can anyone please help!

Upvotes: 1

Views: 1189

Answers (3)

user900202
user900202

Reputation:

try this:

$("div.projectTeamTools").html('Organize by Project Teams: <select id="projectTeams"><c:forEach var="projectTeam" items="${userProjectTeams}"><option value="${projectTeam.projectId}" >${projectTeam.projectName}</option></c:forEach></select>');


    $("#projectTeams").change(function () {
        onTeamSelect($(this).val());
    });

function onTeamSelect(teamId){
        alert(teamId +" Selected");
}

Upvotes: 1

Raheel
Raheel

Reputation: 5163

May be your javascript is disabled in chrome/IE This can be used to enable javascript in chrome Go to start->Run and enter following "C:\Documents and Settings\%username%\Local Settings\Application Data\Google\Chrome\Application\chrome" -enable-javascript

Upvotes: 0

antyrat
antyrat

Reputation: 27765

Option element is very poorly supports events such as onclick.

This is a known issue in WebKit based browsers.

You need to use onchange event on <select> element instead.

For example:

<select id="projectTeams" onchange="onTeamSelect(this.options[this.selectedIndex].value)">

Upvotes: 0

Related Questions