0

I'm doing a questionnaire/survey using HTML. I need to get the value of the checkbox that is being checked. The questions on the next page(L2) will be based on the questions that is only checked on the checkbox when i click "submit".

I have a problem in getting and storing the value of the checkbox and using it later for an IF else-If else statement. Read a lot of online materials but I can't see any light from this. Any help will do... here is the code of the plain checkbox.

<html> 
    <head> 
    </head>
    <body>
        <script>
            var vg = document.getElementId("VideoGame").checked;
            var te = document.getElementId("Text").checked;
            var an = document.getElementId("Animals").checked;
            var sp = document.getElementId("Sports").checked;
            var lo = document.getElementId("Logo").checked;
        </script>
        <form action="L2.html">   
            Check the box if applicable: <br>
            <input type="checkbox" name="Q1" id="VideoGame"> The image is a Video Game. 
            <br>
            <input type="checkbox" name="Q1" id="Text"> The image contains text. <br>
            <input type="checkbox" name="Q1" id="Animals"> The image is about animals. 
            <br>
            <input type="checkbox" name="Q1" id="Sports"> The image is about sports. 
            <br>
            <input type="checkbox" name="Q1" id="Logo"> The image contains a logo. <br>
            <input type="submit" value="NEXT"> 
        </form>
    </body>
</html>
StuntHacks
  • 457
  • 3
  • 15

4 Answers4

0

You can simply add onclick to every input-element:

<input type="checkbox" name="Q1" id="VideoGame" onclick="refreshValues()" />

The refreshValues()-function can look like this:

function refreshValues() {
    var vg = document.getElementId("VideoGame").checked;
    var te = document.getElementId("Text").checked;
    var an = document.getElementId("Animals").checked;
    var sp = document.getElementId("Sports").checked;
    var lo = document.getElementId("Logo").checked;
}
StuntHacks
  • 457
  • 3
  • 15
0

I would consider storing the data in either LocalStorage or SessionStorage and then retrieve it on the next page with localStorage.set('key', 'item') and localStorage.get('key');

https://developer.mozilla.org/en/docs/Web/API/Window/localStorage https://developer.mozilla.org/en/docs/Web/API/Window/sessionstorage

And if you need to store an object with multiple inputs consider using JSON stringify.

Storing Objects in HTML5 localStorage

daskel
  • 88
  • 1
  • 10
0

Try to store user-answers in cookies, that might help. Ref: https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie

0
if($("#your check box input field id").is(":checked")){
local jquery variable="yes";
}
else{
m11="no";
}

try this ,this is jquery code that will help u store the values in db.if u just wanna put conditions u can see the way i used it in condition. hope its helpfull. see this if u are still confused. saving values of toggle(yes or no) in database php. check box and toggle work same way.

Archelese
  • 21
  • 9