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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting name of dropdown from dynamically created list of dropdowns

Status
Not open for further replies.

abenny2001

Programmer
Feb 4, 2009
3
Hey Guys,

I have a situation where I have a list of dropdowns dynamically created in my for loop in JSP code. Now I need the name of dropdown on onClick[is that right choice?] so that I can play around with dojo APIs with dijit.byId(name). I tried by some logic:

var dropdowns = document.getElementsByName("db");

and then messed up with errors getting function/variable not defined. Any tip/help/snippet appreciated.Thank you.
 
If you want to use "dijit.byId", then I'm guessing (as the nsame implies) you simply pass in the ID as a string - no need to mess around with getElementsBy... methods.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Hmmm... and if you need the ID in the onchange event, you can refer to 'this.id':

Code:
<select id="wibble" onchange="alert(this.id)">

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Sorry I should have made it clear....

So I am generating multiple rows of dropdowns (say n )in for loop..

Each row has 3 dependent dripdpwn so I cannot use Onchange as it is reserved for this event.

//JSP
for(int i=0;i<length;i++){

1st row select name[and id are same] =d11<%=i%>,d12<%=i%>,d13<%=i%>
2nd row select name =d21<%=i%>,d22<%=i%>,d23<%=i%>
................................

nth row..............

}//end for

So my ojective is how to get dijit.byid(d11<%i%>)
dijit.byid(d12<%i%>)
dijit.byid(d13<%i%>)
.....................on one event of Onchange. get value i
Note that OnChange is already ised for depenedent population.








}
 
That code gives nothing away. Can you post real client-side code?

Also, what do you mean when you say 'I cannot use Onchange as it is reserved for this event'? Any select element can have its own onchange event.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
<script type="text/javascript">
function getDataForCenterStore(selectedValue){
var secondStore = new dojo.data.ItemFileReadStore({ url: "<%=servletPath%>?selectedArea="+selectedValue});

dijit.byId("*****What should I give here*****).store =
//////

}
</script>
///========================jsp============================
<%
for(int i=0;i<l.size();i++){
%>
<tr>
<input type="hidden" name="id" value="<%=i%>" />
<% UserDTO user = (UserDTO) users.get(i);

String eno = user.getid();%>
<input type="hidden" name="eno<%=i%>" value="<%=nuid%>" />
<td><%=user.getName()%></td>

<td><div align="right">Area<br />
Center<br />
Location</div></td>
<td><div class="tundra">
<input dojoType="dijit.form.FilteringSelect"
store="firstStore"
name="firstStore<%=i%>"
searchAttr="area"
onChange="getDataForSecondStore"

id="areaid<%=i%>"
/> </div>

<div class="tundra">
<input dojoType="dijit.form.FilteringSelect"
store="secondStore"
name="secondStore<%=i%>"
searchAttr="center"
onChange="getDataForThirdStore"

id="centerid<%=i%>"
/> </div>
<div class="tundra">
<input dojoType="dijit.form.FilteringSelect"
store="thirdStore"
name="thirdStore<%=i%>"
searchAttr="location"
id="locationid<%=i%>"
/> </div>
</td>
</tr>
<%}%>
 
How is that, by any stretch of the imagination, client-side code?

That is server-side code. Can you post the client-side code?

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top