Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IE option tag onclick alternative

Status
Not open for further replies.

mabrite

Programmer
Joined
Mar 8, 2006
Messages
3
Location
US
Hello all,

I'm sure this question has been asked before... but I'll take a swat and pray for forgiveness...

here goes:

i understand that IE does not support onclick events in the option tag. i also understand that the typical workaround for this problem is to use the select tag instead. unfortunately, using the select tag for the onclick event is not possible in my situation. i've included some pseudocode below to illustrate the problem. anybody have a solution??? thanks in advance (and afterwards too!)

<form name="form#1">
<select>
<%
open jdbc connection to mssql
open record set
while rs.next
thisRecord = getParameter...
%>
<option onclick="updateThisRecord(thisRecord);">...this will never work...</option>
<%
closing stuff
%>
</select>
</form>

<form name="form#2">
<input name="updateMe" type="hidden" value="">
<input type="button" onclick="form.submit()">
</form>

<script>
function updateThisRecord(thisRecord) {
form#2.updateMe.value==thisRecord
}
</script>

explanation: ideally the user will select the option, send "thisRecord" to the "updateThisRecord" function which will in turn update the value of the hidden element in form#2. the button in form#2 submits the form (action="#") and the value is read via getParameter for the next go-around.

i really hope that makes some sense...

thanks!
mark
 
You can do this using the <select> tag... you say you can't modify the <select> tag - this poses a problem... but let's get to that later. Here is how you would use the <select> tag and onchange attribute to call a function (that justs alerts the value of the option selected):
Code:
<select onchange="updateThisRecord(this.value)">
  <option value="1">One</option>
  <option value="2">Two</option>
</select>
...
<script type="text/javascript">
function updateThisRecord(_data) {
  alert(_data);
}
</script>
Now... you mentioned you couldn't alter the <select> tag. If this is the case, is there a way to identify the <select> tag? Does it have an ID on it? If you can get an ID put on it - or you can identify it as the Xth select in the Yth form of the page... then you can do this using javascript as well.

You could attach the onchange attribute to the target <select> by including some javascript on the page that triggers once the page has loaded.

Let us know how you go,
Jeff

[tt]Jeff's Page @ Code Couch
[/tt]

What is Javascript? FAQ216-6094
 
OK... more info:

The problem is that the select tag has to be before the database connection is opened and the record read from the stored proc. So the javascript call "updateThisRecord(<%=aRecord%>)" is sending a null value. i have played around with the idea of using a counter to indentify when rs.next is on its first pass and then creating the select tag, but this is very messy and would create a situation where the select tag is only created if there is a resultset to return (which often times there wont be and i will need to display an empty select box).

Its entirely possible that i am convoluting the issue. I will continue to think this through and look for the most simple solution. any ideas/suggestions are welcomed and most appreciated.

thanks again,
mark
 
I think you're misunderstanding what Jeff and Cory are saying. Here's your psuedo code slightly modified.
Code:
<form name="form1">
<select[b] onchange="updateThisRecord(this.value)"[/b]>
<% 
open jdbc connection to mssql 
open record set
while rs.next
thisRecord = getParameter...
%>
<option [b]value="<%=thisRecord%>"[/b]>...this [i]should[/i] work...</option>
<%
closing stuff
%>
</select>
</form>

<form name="form2">
<input name="updateMe" type="hidden" value="">
<input type="button" onclick="form.submit()">
</form>

<script>
function updateThisRecord(thisRecord) {
  document.form2.updateMe.value=thisRecord;
}
</script>

Adam
 
Adam,
Yes, you were correct. This issue has been resolved.
Thanks,
Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top