SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2004
    Location
    Albany, N.Y.
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    capture text selected in a select tag

    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

  2. #2
    SitePoint Enthusiast
    Join Date
    Jul 2004
    Location
    Albany, N.Y.
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •