Reputation: 1799
i am unsure why my code does not work, any help would be much appreciated
i am trying to create a jquery function where by, when a user clicks on an image (e.g:
messaging-img
) the input field take up the value101010
| when a user clicks on theunlimited-img
the input field take up the value202020
. could one kind;y advise me on this - thank you
$(document).ready(function () {
$(".messaging-img").on("click", function(){
$("#paypal-ref-111").val("101010");
});
$(".unlimited-img").on("click", function(){
$("#paypal-ref-222").val("202020");
});
$(".basic-img").on("click", function(){
$("#paypal-ref-333").val("303030");
});
});
<div class="" id="paypal_express_checkout"><input type="" checked="checked" id="paypal-ref-111" id="paypal-ref-222" id="paypal-ref-333" value=""/></div>
Upvotes: 1
Views: 72
Reputation: 2108
Here is a working solution:
Firstly, I have updated your input field to contain only one ID, named paypal-ref
. An element can only contain one ID and it must be unique.
<input type="" checked="checked" id="paypal-ref" value=""/>
Secondly, your jQuery has been updated accordingly:
$(document).ready(function() {
$(".messaging-img").on("click", function() {
$("#paypal-ref").val("101010");
});
$(".unlimited-img").on("click", function() {
$("#paypal-ref").val("202020");
});
$(".basic-img").on("click", function() {
$("#paypal-ref").val("303030");
});
});
You can see a demo here
Upvotes: 1