0

I'm trying to create a form that brings the order number to the client select "Yes" or "no" this is my code

Contato.phtml

...
        <li>
            <label for="f_f_compra" class="required"><em>*</em><?php echo Mage::helper('contacts')->__('Já realizou sua compra?') ?></label>
                <div class="select">
                    <select id="f_f_compra" name="f_f_compra" class=" required-entry required-entry select">
                    <option value="" selected="selected">-- Selecione --</option>
                    <option value='Sim' >Sim</option>
                    <option value='Não' >Não</option>
                    </select>
                </div>
        </li>
            <li id="pedido" style="display:none;" >
                    <li class="wide">
                        <label for="pedido" class="required"><em>*</em><?php echo $this->__('Pedido') ?></label>
                        <div class="input-box">
                            <input name="increment_id" id="increment_id" value="" class="input-text required-entry" type="text">
                            <input name="pedido" id="pedido" value="0" type="hidden">
                        </div>
                    </li>
...

JQuery code

$jQuery('#f_f_compra').change(function(){
    if ($(this).val() == "Sim") {
        document.getElementById("pedido").style.display="block";
        //jQuery alternative
        //$("#attach").show();
    } else {
        document.getElementById("pedido").style.display="none";
        //jQuery alternative
        //$("#attach").hide();
    }
});

1 Answer 1

0

You could try below:

document.getElementById("f_f_compra").onchange = function(){
    if (document.getElementById("f_f_compra").value == "Sim") {
        document.getElementById("pedido").style.display="block";
    } else {
        document.getElementById("pedido").style.display="none";
    }
};

https://jsfiddle.net/ankgnvxg/2/

Also in my fiddle i changed the nested li elements

24
  • Thanks for the help, you are giving this error: Uncaught TypeError: Can not set property 'change' of null Commented Jul 25, 2017 at 18:22
  • Have you copied it exactly like in the fiddle above i have not got change in my code but onchange
    – harri
    Commented Jul 25, 2017 at 18:25
  • What should I do? Commented Jul 25, 2017 at 18:33
  • Did you get it going?
    – harri
    Commented Jul 25, 2017 at 18:36
  • I'm doing a lot of research here, I think it might be a conflict between the prototype of magento and JQuery that I downloaded, but I already did the noconflict file so I think it might be blocking my jquery Commented Jul 25, 2017 at 19:13

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.