1

I'm trying to do hide and show of several select and text fields

the idea is that in the first field when "Banco" is selected it shows a dropdown for the user to select which bank, till that part everything works perfectly fine, the problem comes when in the next "banco" dropdown people select "otros" it should show a text field for the costumer to write the name of the bank, but I have done everything and can't seem to make it work

Can you help me please??

this is the JS

function formapago() {
if (document.getElementById('infopago').value == 'banco') {
    document.getElementById('banco').style.display = '';
    document.getElementById('tipopago').style.display='';
    }   

else {
          document.getElementById('banco').style.display = 'none';
          document.getElementById('tipopago').style.display='none';
}

if (document.getElementById('infopago').value == 'mp') {
    document.getElementById('mpcobro').style.display = '';
} else {
          document.getElementById('mpcobro').style.display = 'none';
}  
if (document.getElementById('banco').value == 'otros') {
    document.getElementById('otrosban').style.display = '';
    }   

else {
          document.getElementById('otrosban').style.display = 'none';
}   

}

and HTLM

<select name="infopago" id="infopago" onchange='formapago()'>
          <option value="elegir" selected="selected">Elegir</option>
          <option value="banco">Banco</option>
          <option value="mp">Mercado Pago</option>
        </select>
        </p>
        <div id="banco" style="display: none">
      <p><strong>BANCO: </strong></p>
      <p>
        <label for="banco">Banco Emisor</label>
        <select name="banco" id="banco" onchange='formapago()'>
          <option value="elegir" selected="selected">Elegir</option>
          <option value="provincial">Provincial</option>
          <option value="mercantil">Mercantil</option>
          <option value="banesco">Banesco</option>
          <option value="venezuela">Venezuela</option>
          <option value="otros">Otro</option>
        </select>
      </p> </div>

      <div id="otroban" style="display: none">
      <p>
        <label for="otroban">Otro Banco</label>
        <input type="text" name="otroban" id="otroban"/>
      </p>
      </div> 
5
  • You really should be using a javascript framework like jQuery. It makes issues like this pretty trivial. Commented Feb 5, 2013 at 6:44
  • I tried to use jQuery but I'm already using it as it's a form converted in wizard and for some reason jQuery code doesn't work, that is why I'm trying to do it this way, if you could help me I would appreciate it Commented Feb 5, 2013 at 6:46
  • Put this in a Js fiddle and we can fix it. Nothing complicated. Commented Feb 5, 2013 at 6:48
  • Which wizard plugin you are using? Commented Feb 5, 2013 at 6:49
  • I'm using this one jankoatwarpspeed.com/… and it works great but my boss wants to the fields to appear of thin air and that it was working great till that second dropbox Commented Feb 5, 2013 at 7:01

1 Answer 1

2

Your problem is that you have two element with same ID.

This part :

  <div id="banco" style="display: none">
    <p><strong>BANCO: </strong></p>
    <p>
      <label for="banco">Banco Emisor</label>
      <select name="banco" id="banco" onchange='formapago()'>
       <option value="elegir" selected="selected">Elegir</option>
       <option value="provincial">Provincial</option>
       <option value="mercantil">Mercantil</option>
       <option value="banesco">Banesco</option>
       <option value="venezuela">Venezuela</option>
       <option value="otros">Otro</option>
       </select>
    </p> 
 </div>

div and select element have id="banco". Try to change select id.

EDIT

Here some problem i found when i see your HTML :

  1. Multiple element with same id.
  2. In your javascript, it try to get tipopago and mpcobro element, where is the element ?
  3. I think this part :
  document.getElementById('otrosban').style.display = '';

Should be :

  document.getElementById('otroban').style.display = '';
Sign up to request clarification or add additional context in comments.

1 Comment

Hi I didn't include that the part of tipopago or mpcobro because those 2 are working perfectly fine... But I'm glad to say that with the id change and the otroban that scaped my eyes (must be because it's 2:45am) it's fixed!! Thank youuuuu!!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.