Tuesday, 15 July 2014

javascript - how do I set some default value for a check box or a radio button if user do not check the check box or select a button -


I have a dynamically formatted form using the bootstrap form elements, in which I have a check box and radio There are options to add buttons. When I click the submit button, the data is sent to the database as json in the form. I am using the following javascript function to submit the form

  $ ('# customform'). ("Submit", function) {var formData = JSON.stringify ($ ("custom form"). SerializeArray ()); var formURL = $ (this) .attr ("action"); $ .ajax ({Url: formURL, Type: "Post", Data: FormData, Content Type: "Application / Jason; Charset = utf-8", Success: Work (Data) {$ ("# myAlert"). Show (); }, Failure: function (error) {}}); event.preventDefault ();});  

The problem is that, whenever the check box is left unchecked or no option is selected for the radio button, then no data is sent to the database related to these areas. is.

Is there any way I can use to set some default values ​​for these form fields so that I get some value in the database for these areas, even if the fields are not selected.

In addition to the comments of Mark B, you can also set default values ​​in the database for those fields, which are normally set to use the checkbox as separate.


No comments:

Post a Comment