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

capture text selected in a select tag

Status
Not open for further replies.

mcghee31

IS-IT--Management
Dec 13, 2007
12
US
I have a simple select tag on a form

<select name="req" id="req' >
<option value="1">James Young</option>
<option value="2">Kebu Steward</option>
<option value="3">Randy Clarke</option>
</select>


How can I capture the text of the selected item.
example suppose "Kebu Steward" was selected by the user

how could I capture "Kebu Steward" in one value then break it into two
values
var f_name = Kebu
var l_name = Steward

This is my first time with such and issue and I don't know how to approach the problem.

Thanks
 
Found some reading material that helped solve the issue.

Code:
<script type="text/javascript">
function  passVals(){
        
	//used to get text of selected item in select tag	
	reqList = document.getElementById("req");
	var full_name = reqList.options[reqList.selectedIndex].text;
	
	//separate full name in an array
	var fl_name = full_name.split(" ");

	//assign values to parent elements
	window.opener.document.appts.req_f_name.value= fl_name[0];
	window.opener.document.appts.req_l_name.value= fl_name[1];
	window.close();
}
</script>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top