Save result checkboxes checked in form into sqlite database with javascript

前端 未结 1 1294
清酒与你
清酒与你 2021-01-28 23:21

I have a form in my app with several checkboxen. I want the result(value) of the checked checkedboxes saved into separate rows in the database, see below. The problem is that wh

相关标签:
1条回答
  • 2021-01-28 23:52

    I think the problem is because of your for loop being terminated by a semicolon:

    for (var r= 0; r < elementen.lenght; r++);
    

    Try this:

    function insertRecordSafety(txb) {
    
    var elementen = document.getElementsByName ("checkgroup");
    var tmpChoise;
    
        for (var r= 0; r < elementen.length; r++)
        {
            if (elementen[r].checked) 
            {
                tmpChoise = elementen[r].value; 
                alert(tmpChoise);
                var sqlStrB = 'INSERT INTO testSafetyBeter (beter) VALUES (?)';
                txb.executeSql(sqlStrB, [tmpChoise], onSqlSuccess, onSqlError);
            }
        }
    }
    

    I've also spaced things out to make it easier to read.

    0 讨论(0)
提交回复
热议问题