0

I am trying to a check box in a form to output something like a 0 or 1 or Y and N, just something to tell me if it was checked or not.

<input type="checkbox" name="bridal" placeholder="Bridal" value="yes">

This is what I have as an example and no matter what I have done so for, it just says 'ON' in the SQLlite database.

Can anyone give me a bit of insite as to where I should be looking?

Thanks.

function insertDB(tx) {
            var _full_name = $("[name='full_name']").val();
            var _email = $("[name='email']").val();
            var _bridal = $("[name='bridal']").val();
            var _bridesmaids = $("[name='bridesmaids']").val();
            var _flowergirls = $("[name='flowergirls']").val();
            var _mens_hire = $("[name='mens_hire']").val();
            var _accessories = $("[name='accessories']").val();
            var sql = 'INSERT INTO DEMO (full_name, email, bridal, bridesmaids, flowergirls, mens_hire, accessories) VALUES (?,?,?,?,?,?,?)';
            tx.executeSql(sql, [_full_name, _email, _bridal, _bridesmaids, _flowergirls, _mens_hire, _accessories], sucessQueryDB, errorCB);

        }
5
  • That checkbox is either going to send "yes" or it won't be a successful control and won't appear in the sent data at all. It won't send "ON". Commented Jan 22, 2016 at 19:59
  • The HTML5 placeholder attribute is not a substitute for the label element … and won't work at all on a checkbox. Commented Jan 22, 2016 at 19:59
  • I have tried it the following way <input type="checkbox" name="bridal" value="yes"> and checked or unchecked its entering yes into the database. Commented Jan 22, 2016 at 20:19
  • @Doonie — Assuming you have it in a form, then all that will do is send either "yes" or nothing at all to the server. How you get from there to putting anything in the database depends on the server side code you haven't shown us. Commented Jan 22, 2016 at 20:39
  • added function to main question. Commented Jan 22, 2016 at 20:43

1 Answer 1

1

You could do something like:

   var _flowergirls = ($("[name='flowergirls']").is(':checked'))?'Yes':'No';

So check if the val is checked and if so set the appropriate value to enter into the db.

Sign up to request clarification or add additional context in comments.

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.