On select dropdown value how to display textbox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nawedita
    New Member
    • Mar 2010
    • 6

    On select dropdown value how to display textbox

    Hi

    I am facing a problem with my code ....
    this is what I am doing ...
    I am running this dropdown in while loop...and i want when i select Cheque then display textbox otherwise textbox not display. but when i select Cheque on selection function work only for first row not working in other row.
    I am attaching the code snippet as well ... see if you can help ...
    Code:
    <script language="javascript">
    function handleOther(val){ 
    if(val == "Cheque"){ 
    document.getElementById('cheque_no').style.display = ''; 
    }else{                              document.getElementById('cheque_no').style.display = 'none'; }}</script>
    Code:
    <select name="paidmode[]" onChange="handleOther(this.value)">
    <option value="Cash">Cash</option><option value="Cheque">Cheque</option>
    </select>
    <input type="text" name="cheque_no[]" size="12" id="cheque_no">
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    That's because IDs are supposed to be unique. When you use document.getEle mentById() to get an element, it gets the first one that matches the ID.

    Make all IDs unique (e.g. use the row number, cheque_no1, cheque_no2...) and then use that to get the correct element. Alternatively, you could get the collection (document.getEle mentsByName("ch eque_no[]")) and then loop over them to find the correct element.

    Comment

    Working...