问题
I need to create a javascript array which is populated based on drop down lists' (more than one) selected values, except each drop down list has the same name because they are created in a for loop. Right now I have:
<script language="JavaScript">
var array = [];
var e = document.getElementById("phItemStatusID").value; //returns first ddl value
</script>
and later in the asp code is my drop down list which is populated from a database using VBScript:
<%for i = 0 to UBound(photoItemsArray,2)%> //for each item, generate DDL
<select name="phItemStatusID">
itemStatusID = photoItemsArray(6,i) //get current selected value
for j = 0 to UBound(photoStatusesArray,2)%> //for each possible status
<option value="<%=photoStatusesArray(0,j)%>"
<%if photoStatusesArray(0,j) = itemStatusID then%>
selected
<%end if%>>
<%=photoStatusesArray(1,j)%>
</option>
<%next%>
</select>
next%>
This works in situations where there is only one dropdown list generated. The problem I'm running into involves instances where there is more than one drop down list with the name phItemStatusID.
var e = document.getElementById("phItemStatusID").value; only returns the first drop down list's values and the others are ignored. How do I obtain them?
回答1:
document.getElementById("phItemStatusID").value will get the value of first element with an ID of "phItemStatusID" because IDs in HTML are supposed to be unique.
If you want to get the value of a second box, use a different ID.
来源:https://stackoverflow.com/questions/11672855/classic-asp-javascript-array-populated-by-vbscript-drop-down-list