View Full Version : Need Help with Drop down menu w/Option box.

06-10-2010, 01:56 AM
I have a form I'm trying to use java script to work with my drop down. I'm told that I donít have any functionality to change the name of the fields. How do I add some JavaScript to change the name of the select box from ssl_amount to something else and the name of the text box that appears to ssl_amount.

<script type="text/javascript">
function toggleField(val) {
var o = document.getElementById('ssl_amount');
(parseInt(val) == 000)? o.style.display = 'block' : o.style.display = 'none';
<select name="ssl_amount" id="ssl_amount" onChange="toggleField(this.value);">
<option value="0" selected>Select Amount</option>
<option value="000">Other</option>
<input type="text" name="other" id="ssl_amount" style="display: none;">

06-10-2010, 09:57 PM
I'm not sure why you are trying to set a text field with the select option value but only display it if it is '000' :confused:
But if that is your desire, then:

<title>SBox change</title>

<script type="text/javascript">
function toggleField(info) {
var o = document.getElementById('ssl_amount');
o.value = parseInt(info).toFixed(2);
o.style.display = (info == '000') ? 'block' : 'none';
<select name="ssl_amount" onchange="toggleField(this.value)">
<option value="0" selected>Select Amount</option>
<option value="2400">2400.00</option>
<option value="1000">1000.00</option>
<option value="500">500.00</option>
<option value="250">250.00</option>
<option value="100">100.00</option>
<option value="50">50.00</option>
<option value="1">1.00</option>
<option value="000">Other</option>
<input type="text" name="other" id="ssl_amount" value="" style="display:none">

If you are trying to display the text only if the selection is 'other' and allow user to enter a number,
then you will need to modify script above a bit.

Also note that you must make the id value unique. You cannot have 2 elements named 'ssl_amount'

It would also be helpful to enclose you script between [ code] and [ /code] tags (without the spaces)
to make it easier for forum members to read and/or copy.