Link to home
Start Free TrialLog in
Avatar of Ronak Vora
Ronak VoraFlag for India

asked on

How to Change checkbox value after clicked and submit to form?

i have an jQuery with html

    <input type="checkbox" name="<portlet:namespace/>push" id="pushnotifications" value="1" checked="checked" />
                           push notifications<br> <br>
                           
In this input text i want to add jquery for changing value after clicked how can i got it?
Avatar of Misha
Misha
Flag of Russian Federation image

Try to use submit event:
<form id="target" action="YourAction.html">

 <input type="checkbox" name="YourName" id="pushnotifications" value="1" checked="checked" />
</form>
$( "#target" ).submit(function( event ) {
$( "#pushnotifications" ).prop('checked', true);
  event.preventDefault();
});

Open in new window

just replace "11111111111111111" by what you want :
jQuery(function($) {
       $("#button").click(function() {
               $("#pushnotifications").val(11111111111111111);
       });
});
</script>
<body>
<form>
<input type="checkbox" name="<portlet:namespace/>push" id="pushnotifications" value="1" checked="checked" />
                           push notifications<br> <br> 
<input type="submit" value="submit" id="button">
</form>

Open in new window

What is the reason for wanting to change the value?
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.