www.webdeveloper.com
Results 1 to 2 of 2

Thread: Dropdown list and document.getElementById

  1. #1
    Join Date
    Nov 2011
    Posts
    31

    Dropdown list and document.getElementById

    Hi,

    I have a form that displays data from the database. In this form I have a field that is a dropdown list:

    Code:
    <div id='subform_grade_udetails0026l332t598' style='position:absolute;top:598px;left:332px'>
                                          <select name="subform_grade_udetails0026udetails_cos" id="subform_grade_udetails0026udetails_cos" class="objects" style="width:80px;" onchange="untick('subform_grade_udetails0026', this);uDB(this);calcStatus();" onfocus="nuSetRow('subform_grade_udetails0026');" >
                                                    <option value=''></option>
                                                    <option value='Failed'>Failed</option>
                                                    <option value='Passed'>Passed</option>
                                            </select>
    
                                       </div>
    With javascript I'm trying to assign a value to this field by using:

    Code:
    document.getElementById('subform_grade_udetails0026udetails_cos').value= 'Failed';
    But it doesn't work.
    Is this the correct way to assign a value to a dropdown field?

    Thank you!
    RESA

  2. #2
    Join Date
    Nov 2011
    Posts
    31
    Hi,

    I have tried to use:

    Code:
    setSelectedIndex(document.getElementById('subform_grade_udetails0026udetails_cos'),"Failed");
    
    function setSelectedIndex(s, v) {
    for ( var i = 0; i < s.options.length; i++ ) {
    if ( s.options[i].text == v ) {
    s.options[i].selected = true;
    return;
    }
    }
    }
    I seen that the dropdown box is filled with "Failed". When I save fields are getting blank.
    In the code I see that the "Failed" option is not "Selected" and I don't understand why.

    Could you please help me with this?

    Thank You!
    RESA

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