First of all, you can significantly improve your code:
function showText(){ var value = document.getElementById('options').value; if(value == '-1'){ //Other document.getElementById('hidden').style.display = 'block'; } else { document.getElementById('hidden').style.display = 'none'; var amount = document.getElementById("amount"); amount.value = value; document.getElementById('show').innerHTML = "<br><br><font size =+1><b>Amount P " + value + "</b></font>" document.getElementById('show').style.display = "block"; } }
If you changed your html to:
<select name="choices" id="options" onchange="showText()"> <option value="">Select amount</option> <option value="100">100PHP</option> <option value="500">500PHP</option> <option value="1000">1000PHP</option> <option value="-1"> others..</option> </select>
I also suggest adding βhiddenβ input when they select others already in your html, but set it invisible:
<div id="hidden" style="display:none;"class='control-group'> <label class='control-label'>Enter Amount</label><div class='controls'> <input type='text' id='other_amount' name='other_amount' onChange='otherText()'/> </div> </div>
Now that they select others.. with a value of -1 , you want to show an input where they can choose their own value:
if (value == -1) { document.getElementById('hidden').style.display = 'block'; }
Now we only need the otherText() function, which should not be a problem:
function otherText() { document.getElementById('amount').value = document.getElementById("other_amount").value; }
JsFiddle work
source share