Page 1 of 1

JS: disabling/enabling a field based on selectbox input

Posted: Mon Mar 20, 2006 1:11 pm
by roseplant
I have absolutely no knowledge of JS but I just need to use it here if someone can help me with 2 or 3 lines of code.

I have a selectbox, name=h_location_id.
values: 1,2,3...10, 'other'

I have a text box, name=h_location_name , starts off disabled.

Now when the option OTHER is selected in the selectbox I want to enable the text box.

Anyone?

ps just for illustration this is the code i had tried to put together myself which wasnt working at all:

Code: Select all

<script type="text/javascript">
<!--
window.onload = function start() {
document.forms[0].h_location_name.disabled = true;
}

//getSelect(document.forms[0].h_location_id)

function chgtx(a) {


   if (a == 'other') {
      document.forms[0].h_location_name.disabled = false;
   }
}


// -->
</script>


        <select name='h_location_id' onchange='chgtx(javascript:this.value);'>

<option value='1'>1</option>
<option value='2'>2</option>
.
.
.
<option value='other'>Other</option>

</select>

Posted: Mon Mar 20, 2006 1:26 pm
by roseplant
i just figured it out. I removed the "javascript:" bit and it worked fine.

Posted: Mon Mar 20, 2006 1:28 pm
by feyd
you may run into an issue where value isn't a property of the object..

Code: Select all

onchange="chgtx(this.options[this.selectedIndex].value)"