wongadob Posted February 1, 2012 Share Posted February 1, 2012 I am trying to access the value of the element selected in a Select Inputbox. Here is the PHP code I have print"<br/><br/><label class = 'labels'>Allocate all site to</label><select class = 'inputbox' id = 'ReallocAll' name = 'ReallocAll' onchange='change_realloc_fm_all()'>";print "<option value = '0'> </option>"; $y=0;While ($y<$FMListCount){ print "<option value = '".$FMListID[$y]."'>".$FMListName[$y]."</option>"; $y+=1;} This bit of code creates a list with a value that is a database ID of a user and that users actual name. They have been pre grabbed into an array. What I will do in the onchange event is to populate a large table of select input boxes further down the form to this default user. But my first step is to try and find that user number. Here is my Javascript code function change_realloc_fm_all()//--------------------------------------------------------------------------------------------{var FMUserSelected = document.getElementById("ReallocAll");var FMUserID = FMUserSelected.value; result = confirm("Change user ID " + toString(FMUserID));} But I am not getting a User ID value. Instead it just says 'Change user ID [object window] I am sure this code is correct? Can anybody tell me what I am doing wrong. When I have solved this. I will want to write the User ID into several Select inputbox's default values. Is that possibe to set by using say document.getElementById("myNewSelectInputbox").value=FMUserID Any help much appreciated Link to comment Share on other sites More sharing options...
JamesB Posted February 1, 2012 Share Posted February 1, 2012 try this to fetch the user ID: var select = document.getElementById("ReallocAll");var selectedUserID = select.options[select.selectedIndex]; Link to comment Share on other sites More sharing options...
wongadob Posted February 1, 2012 Author Share Posted February 1, 2012 Thanks. I actually removed the toString to see what it was as a value and it was the correct value. Why it would not convert to a string, I do not know. But it now works. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.