bvzrk
bvzrk

Reputation: 1

Pass values taken from an HTML form into a TaffyDB database, located in a seperate .js script

I am trying to take radio and checkbox values from an HTML form, and save/export/pass the values to an external javascript file where the TaffyDB structured database is initialized.

HTML:

            <strong> <font color="black">Color</strong></font>
            <form name="colorForm">
                <input type="checkbox" name="color" value="Red">
                <font color="black">Red
                    <br>
                </font>
                <input type="checkbox" name="color" value="Orange">
                <font color="black">Orange
                    <br>
                </font>
                <input type="checkbox" name="color" value="Yellow">
                <font color="black">Yellow
                    <br>

                <!--function to return checkbox values for colors-->
                <script type="text/javascript">
                    function get_color() {
                        //console.log(document.colorForm);
                        for (var i = 0; i < document.colorForm.length; i++) {
                            while (document.colorForm[i].checked && i < document.colorForm.length) {
                                var check_color = document.colorForm[i].value;
                                return check_color;
                                colorList.insert({color:get_color});
                            }//end of while
                        }//end of for
                    }//end of get_color
                </script>

JavaScript:

var colorList = TAFFY();

Upvotes: 0

Views: 383

Answers (1)

Aniruddha Gohad
Aniruddha Gohad

Reputation: 253

you are returning check_color before you insert in your db.

The return statement ends a function, you cannot execute code after it.

try placing your return statement elsewhere.

Upvotes: 0

Related Questions