jquery - Can not get values from a form in javascript -
i'm trying values of different inputs of form:
<form class="form-horizontal" role="form" id="form_newcours"> <div class="form-group"> <label class="control-label col-sm-2" for="discipline">matiere:</label> <div class="col-sm-4"> <input type="text" class="form-control" id="discipline" placeholder="matiere"> </div> </div> <div class="form-group" align="left"> <label class="control-label col-sm-2" for="datetimepicker">date:</label> <div class="input-group col-sm-4"> <input type="text" class="form-control" id="datetimepicker"/> <span class="input-group-addon"> <span class="glyphicon glyphicon-calendar"></span> </span> </div> </div> <div class="form-group"> <div class="col-sm-offset-2 col-sm-10"> <div class="checkbox"> <label><input type="checkbox" id="creneau_regulier"> ce creneau regulier</label> </div> </div> </div> <div class="form-group"> <div class="col-sm-offset-2 col-sm-10"> <button type="submit" class="btn btn-default" id="btn-newcours">ajouter</button> </div> </div> </form>
and have js code try values of inputs:
$('#btn-newcours').on('click', function(e) { // stop form submitting , let handle following code: e.preventdefault(); // yk: bellow code var jsonstring = json.stringify($('#form_newcours').serializeobject()); console.log($('#form_newcours').serialize()); $.ajax({ type: "post", data: jsonstring, url: "/cours/", contenttype: "application/json" }); });
the function called, variable jsonstring empty. i'm not familiar js, can additionnal div between form , input cause problems ?
edit:
p.s. i'm using plugin serializeobject().
you should add name attribute inputs.
Comments
Post a Comment