www.webdeveloper.com
Results 1 to 5 of 5

Thread: how do i access select form value from a form object

  1. #1
    Join Date
    Jun 2006
    Posts
    6

    how do i access select form value from a form object

    How do i access select form value from a form object passed to a function.

    I can obtain the selected index value, but can't get the text value from the options array.
    e.g.

    HTML Code:
    function validateForm(obj)
    {
      //var radioChecked = false;
      
    	for (var i=0; i<obj.elements.length;i++)
     {
        var elem = obj.elements;
        var currentElement = obj.elements[i];
        var currentType = currentElement.type;
        var currentName = currentElement.name;
        var rGroup = obj[elem[i].name];
    
        var selectIndex = obj.elements[i].selectedIndex;
       [B]var selectText = obj.elements[i].options[selectIndex].text;[/B]
    
    
    	alert('obj.elements['+i+'].name element name is : ' + obj.elements[i].name + '\n obj.elements['+i+'].value is : '
    	+ obj.elements[i].value + '\n obj.elements['+i+'].type is : ' + obj.elements[i].type + 
    	'\n select element index is : ' + selectIndex +
    	'\n selectText is : ' + selectText +
    	'\n i is now : ' + i); 
    	
    ..........

  2. #2
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    you have mistyped. add red:
    Code:
    obj.elements[i].options[obj.elements[i].selectedIndex].text;
    selectedIndex is an attribute of the SELECT object, not of the OPTION object
    Last edited by Kor; 06-23-2006 at 06:40 AM.

  3. #3
    Join Date
    Jun 2006
    Posts
    6
    Thanks for your reply Kor. I have already done this - look at the var selectIndex, and I've tried writing this out in long notation you've given but still get the following error, for this line;

    Error Type:
    Server object, ASP 0177 (0x800401F3)
    Invalid class string

    Cheers
    Last edited by waddy; 06-23-2006 at 09:11 PM.

  4. #4
    Join Date
    Jun 2006
    Posts
    26
    whats with your alert? it confuses me...

  5. #5
    Join Date
    Jun 2006
    Posts
    6
    only using this for debug purposes - and this is only the top part of the script

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles