0

I am using iphone style checkbox with below code. It is showing properly and working fine. But when i submit the form it is not sending any value.

 <div class = "col-sm-6 col-xs-6"  >Gender</div>
<label id="sliderLabel">
    <input id="gender" name="gender" ng-model="formData.gender" type="checkbox" />
    <span id="slider">
        <span id="sliderOn">Male</span>
        <span id="sliderOff">Female</span>
        <span id="sliderBlock"></span>
    </span>
</label>

I am using angular js for client side validation.

Please advise me what am i doing wrong.

Edit:

 formApp.controller('formProfile2', function($scope,$http){

      $scope.formData = {};

        $scope.formprofile2 = function() {

          var allData={'formData': $scope.formData, 'uid': uid}
        $http({
              method  : 'POST',
              url     : 'register.php',
              data : allData,
              headers : { 'Content-Type': 'application/x-www-form-urlencoded' }  
          })

If i click on anyone then it is returning the data(true/false) but i need to return false if not clicked.

2
  • Please share the code where you submit the data and the html template with the <form> tag Commented Jan 22, 2017 at 17:06
  • added angular code. Commented Jan 22, 2017 at 17:09

2 Answers 2

1

please try to use ng-true-value/ ng-false-value with boolean or any numeric value

<input type="checkbox" 
ng-model="checkbox" 
ng-true-value=true 
ng-false-value=false
/>

add condition before the pass formData

    if(!$scope.formData.gender){
 $scope.formData.gender=false;
}
Sign up to request clarification or add additional context in comments.

2 Comments

I tried but it is not working. first i need to place true false under quote. Second thing if i simple submit the form then no value passed. i want unchecked value should passed.
can you add that condition before the pass formdata to alldata
0

The checkbox return undefined if you don't check, So you may use a condition before send the HTTP request.

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.