Reputation: 1799
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>
Upvotes: 0
Views: 1500
Reputation: 20590
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");
});
});
Upvotes: 1