javascript selectBox2 (clearer)
here is a cleaeer version of my question:
<form name="frm">
<select name="sel" onchange="alert('hi');">
<option>blA bla1</option>
<option>blA bla2</option>
<option>blA bla13</option>
</select>
<b onclick="document.frm.sel.options[2].selected=true">Click Here</b>
</form>
how can i make the onChange Event to work when i click on "Click Here"?
thanks again!
[501 byte] By [
fatnjazzy] at [2007-11-19 23:35:25]

# 1 Re: javascript selectBox2 (clearer)
I've never tried this, but how about:eval(document.frm.sel.getAttribute('onchange'));It certainly isn't the most economic way to do it, but it might work.
OK, I just tested this and it doesn't work in IE. Let me do a bit of reconfirguring.
Ok, here is what I came up with. It works, yet it is a painkill. There is likely another solution that I'm too sleepy to find:<form name="frm">
<select name="sel" onchange="alert('hi');">
<option>blA bla1</option>
<option>blA bla2</option>
<option>blA bla13</option>
</select>
<b onclick="document.frm.sel.options[2].selected=true;document.getElementById('g').value=document.frm.sel.getAttribute('onchange');var x=document.getElementById('g').value;if(x.indexOf('{') == -1) { eval(x) } else { eval(x.substr(x.indexOf('{')+1,x.indexOf('}')-x.indexOf('{')-1)) };">Click Here</b>
<textarea id="g" style="display:none"></textarea>
</form>
# 2 Re: javascript selectBox2 (clearer)
Um, why not use onchange()?
<b onclick="document.frm.sel.options[2].selected=true;document.frm.sel.onchange()">Click Here</b>
# 3 Re: javascript selectBox2 (clearer)
I had some sort of error with that in one of the browsers. It might just be my computer because of all the spyware I've had a lot of troubles with Internet Explorer (obviously) and some things don't work. But if that does, certainly go with that.
If I could, and Ive been trying, I'd give you a + rating.
# 4 Re: javascript selectBox2 (clearer)
I had some sort of error with that in one of the browsers.
I tried it in IE, Firefox, and Safari without a problem.