Welcome to the nuBuilder forums!

Please register and login to view forums and other content only available to registered users.

Dropdown list and document.getElementById

Locked
ruiascensao
Posts: 177
Joined: Tue Nov 15, 2011 2:24 pm

Dropdown list and document.getElementById

Unread post by ruiascensao »

Hi,

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

Code: Select all

<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: Select all

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!
Rui
BR
Rui
admin
Site Admin
Posts: 2781
Joined: Mon Jun 15, 2009 2:23 am
nuBuilder Version: 4.5
Been thanked: 1 time

Re: Dropdown list and document.getElementById

Unread post by admin »

rui,

I found this by googling your question..

http://www.webdeveloper.com/forum/showt ... p?t=160118

Steven
ruiascensao
Posts: 177
Joined: Tue Nov 15, 2011 2:24 pm

Re: Dropdown list and document.getElementById

Unread post by ruiascensao »

Hi Steven,

I have tried:

Code: Select all

setSelectedIndex(document.getElementById(PRE+'udetails_func'),"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!
Rui
BR
Rui
admin
Site Admin
Posts: 2781
Joined: Mon Jun 15, 2009 2:23 am
nuBuilder Version: 4.5
Been thanked: 1 time

Re: Dropdown list and document.getElementById

Unread post by admin »

rui,

Its not a nuBuilder question, its a JavaScript question.

You need to either join a JavaScript forum or pay for someone to teach you or do it for you.

Steven
massiws
Posts: 503
Joined: Thu May 24, 2012 2:08 am
Location: Milan, Italy
Contact:

Re: Dropdown list and document.getElementById

Unread post by massiws »

rui,
I hope you've already fixed!
ruiascensao wrote:

Code: Select all

document.getElementById('subform_grade_udetails0026udetails_cos').value= 'Failed';
Is this the correct way to assign a value to a dropdown field?
Maybe you can try to set the ID value instead of 'Failded' value.

Hope this helps.
admin
Site Admin
Posts: 2781
Joined: Mon Jun 15, 2009 2:23 am
nuBuilder Version: 4.5
Been thanked: 1 time

Re: Dropdown list and document.getElementById

Unread post by admin »

.
Locked