0

i simply can not figure out why my code is not working. I've looked into several successful example and applied the same concept but still no success. Any help would be much appreciated

the aim is: when an img is clicked, the input field take up the value stated in the jquery code but this is not working and not sure where i am going wrong

<script>
$(document).ready(function () {
    $(".messaging-img").on("click", function(){
        $("#order_plan").val("messaging");
        $("#order_price").val("0.01");
        $("#paypal_express_checkout input:first").val("1010101");
    });
    $(".unlimited-img").on("click", function(){
        $("#order_plan").val("unlimited wifi");basic wifi
        $("#order_price").val("0.02");
        $("#paypal_express_checkout input:first").val("2020202");
    });
    $(".basic-img").on("click", function(){
        $("#order_plan").val("basic wifi");basic wifi
        $("#order_price").val("0.03");
        $("#paypal_express_checkout input:first").val("3030303");
    });
});
</script>



<div class="table-container">
<table>
    <tbody>
        <tr>
            <td class="left-content">plan:</td>
            <td class="right-content"><input id="order_plan" type="" checked="" value=""/></td>
        </tr>
        <tr>
            <td class="left-content">price:</td>
            <td class="right-content" ><input id="order_price"  type="" checked="" value=""/></td>
        </tr>
    </tbody>
</table>
</div>
3
  • 1
    What is basic wifi in your JS? comments? Any error in console? Commented Jul 22, 2015 at 13:09
  • what exactly is not working? Commented Jul 22, 2015 at 13:09
  • 2
    because of the basic wifi your code is not firing i guess,remove those 2 and try Commented Jul 22, 2015 at 13:10

1 Answer 1

1

It looks like it is working for me. I did notice you have the words "basic wifi" appearing after the semicolon in 2 places in your code. I removed that. Also make sure you have included jQuery, for your jQuery code to work. If you are using Chrome, press f12 to bring up the developer tools and see if you have any errors preventing your code from working.

See the working jsFiddle here

$(document).ready(function () {
    $(".messaging-img").on("click", function(){
        $("#order_plan").val("messaging");
        $("#order_price").val("0.01");
        $("#paypal_express_checkout input:first").val("1010101");
    });
    $(".unlimited-img").on("click", function(){
        $("#order_plan").val("unlimited wifi");
        $("#order_price").val("0.02");
        $("#paypal_express_checkout input:first").val("2020202");
    });
    $(".basic-img").on("click", function(){
        $("#order_plan").val("basic wifi");
        $("#order_price").val("0.03");
        $("#paypal_express_checkout input:first").val("3030303");
    });
});
Sign up to request clarification or add additional context in comments.

Comments

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.