Page 1 of 1

Dropdown list and document.getElementById

Posted: Tue Jun 12, 2012 4:57 pm
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

Re: Dropdown list and document.getElementById

Posted: Wed Jun 13, 2012 7:33 am
by admin
rui,

I found this by googling your question..

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

Steven

Re: Dropdown list and document.getElementById

Posted: Wed Jun 13, 2012 11:02 am
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

Re: Dropdown list and document.getElementById

Posted: Thu Jun 14, 2012 1:48 am
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

Re: Dropdown list and document.getElementById

Posted: Wed Jul 11, 2012 11:32 am
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.

Re: Dropdown list and document.getElementById

Posted: Fri Jul 20, 2012 12:07 am
by admin
.