Rajeev
Rajeev

Reputation: 46969

checkbox value not sent to the views in django

If the checkbox is cheked then only i see the value else not on submit what am i doing wrong

 <form>
 <input type="checkbox" id="tagdata" name="tagdata" onchange="get_checkbox_value();" value="0"/>
 </form>

function get_checkbox_value()
{
if ($('#tagdata').attr('checked')) {
  $('#tagdata').val('1');
}
else
{
  $('#tagdata').val('0');
}
}

Upvotes: 0

Views: 506

Answers (2)

user1481793
user1481793

Reputation: 553

if i am right about what you are asking use this one and i am sorry about code formate .

<html>
<head>       <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
</head>
</body>
<form>
 <input type="checkbox" id="tagdata" name="tagdata" onchange="get_checkbox_value();" />
 </form>
<script>
function get_checkbox_value()
{
if ($('#tagdata').attr('checked')) {

   $('#tagdata').val('1');

}
else
{


  $('#tagdata').val('0');

}
}

</script>
</body>
</html>

Upvotes: 0

KayEss
KayEss

Reputation: 2300

I'm not sure exactly what you're asking, but checkbox values are only submitted if the checkbox is ticked/crossed. If a value is submitted then the user has selected the checkbox, if no value is submitted then it is not checked.

Upvotes: 3

Related Questions