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

dynamic dropdowns

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi,
I'm dynamically building my dropdown (<select option>) with the code something like this:
<select name=&quot;1stSelect&quot;><option value=&quot;&quot; selected></option>
<script language=&quot;javascript&quot;>
<% using some java, I loop and populate the description and aName%>
var description= &quot;<%=description%>&quot;;
var s = &quot;<%=aName%>&quot;;
document.write(&quot;<option value='&quot; + description + &quot;&&&quot;+ s+&quot;'>&quot; + description);
<%} %>
</script>
</select>

The problem is I'm using the exact code to populate another select with the same items in the dropdown....

Since I'm looping through a lot of data, I'm wondering, is there a way to build these two selects inside one loop using the above code, to boost the performance?

Thanks a lot.


 
jaredn,

I understand the clonenode, but what do you mean about the array.join(&quot;&quot;), can you elaborate on the join?

thanks
 
Well, first off, string concatenation is slow in js. So you want to do as little of that as possible. What you may wish to do, is store each select option string in an array inside your loop, and then join them:

somestr = myopsarray.join(&quot;&quot;)

then you can call:

document.write(somestr)

once for each select box... that could speed things up a bit jaredn@eae.net -
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top