Forum Moderators: open

Message Too Old, No Replies

onclick() event is not working on <select>

Javascript onclick() event in not working on <select>

         

nitinsingh

7:15 pm on Mar 30, 2009 (gmt 0)

10+ Year Member



Hi,
I am using Windows Mobile 5.0 for my client application in JAVA (JSP & SERVLET).There i am using a
dropdown menu on a JSP page.There are 3 different values (A,B,C) in that drop box.My question is that....when i select/change any value from that dropdown menu,color of this row (the row containing dropdown menu)should be changed.There is different color for each value in that dropdown menu.(green for A,red for B,gray for C)
I am using following JAVASCRIPT code in my JSP page,that is working successfully on Desktop PC.
-----------------------------------------------------------
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
<script language = "javascript">
function check(aa)
{
document.getElementById("glow").style.backgroundColor=document.getElementById('abc').value;
}
</script>
</head>

<body>

<form method="POST" action="--WEBBOT-SELF--">
<p>&nbsp;</p>
<p>&nbsp;</p>
<table border="1" width="100%">
<tr id="glow">
<td width="324" >&nbsp;</td>
<td><select size="1" name="D1" onclick="check(this.value)" id="abc">
<option value="green">A</option>
<option value="red">B</option>
<option selected value="gray">C</option>
</select></td>
</tr>
<tr>
<td width="324">&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td width="324">&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
</form>
</body>

</html>
-----------------------------------------------------------
This code is working successfully on Desktop PC(on IE) but it is not working on Windows Mobile 5.0(Mobile IE).(Colors are changed on Desktop but not on(WM 5.0)).

Kindly guide me how can i use onclick() javascript event on Windows Mobile 5.0.

whoisgregg

4:03 pm on Mar 31, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld, nitinsingh!

I'm not familiar with the javascript quirks of Windows Mobile 5.0. One thing I would check is to see if the onclick event is firing at all. replacing your onclick with something like this would tell you if it's firing at all:

onclick="alert(this.value);"

If the onclick doesn't fire at all, it may be a problem with what type of elements that browser allows the onclick event for. Since it's a select, you could try the "onchange" event.

nitinsingh

10:18 am on Apr 5, 2009 (gmt 0)

10+ Year Member



yup..onchange() event is working.Initially i used it.But it does not fullfill my purpose.but onclick() can do it.and onclick() is not being fired when i tried onclick="alert(this.value);"

DrDoc

4:49 pm on Apr 5, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld!

IE does not handle

onclick
on
select
elements, if I remember correctly, although FF does.

Looking at your code, I honestly cannot see why

onchange
would not work. Seems like it should. For that matter, seems like you should be able to make it work otherwise.

Perhaps if you told us why

onchange
does not fulfill your purpose?

nitinsingh

12:09 pm on Apr 8, 2009 (gmt 0)

10+ Year Member



Actually when i use onchange(),it changes color only when the value in the drop box is changed.i.e. from (A-->B),(A-->C),(C-->A)....but if i click A and select A again (does not change value),then it does not change color(color is same as it was previously set.If color is red,the it remains red,if color is green then it remains green).But I want to change color when i click the drop box.!

DrDoc

5:10 pm on Apr 8, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If A is selected (green), why does it need to be reset to green again? Should it not be the same color?

nitinsingh

4:58 am on Apr 9, 2009 (gmt 0)

10+ Year Member



Nop.......actually i want to ensure that i have clicked 'A'.So color sholu be changed every time when i click on that drop box value.

nitinsingh

5:31 am on Apr 9, 2009 (gmt 0)

10+ Year Member



My default value in that drop box is 'A'(Ist no.).so when i click on 'A' and remains it 'A',then it's color should be changed/reset to give me confirmation of being clicked.

DrDoc

6:29 pm on Apr 9, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That is extremely counter intuitive and breaks usability. If you do not change a value, you want something else to still change? Awkward.

Fix your code instead. Add a blank option so that the user is forced to change to A, B, or C.

Onclick
does not work on a
select
anyway, so it is not like there is an option.

Either:
a) live with the fact that an unchanged select box results in no changes being made
or
b) force the select box to be changed