0

i have:

var answers = [];

                var frage1 = document.getElementById("frage1").innerHTML;
                frage1antwort1 = $('#frage1antwort1:checked').length; f.Example Value = 0
                frage1antwort2 = $('#frage1antwort2:checked').length; f.Example Value = 0
                frage1antwort3 = $('#frage1antwort3:checked').length; f.Example Value = 1

                var frage2 = document.getElementById("frage2").innerHTML;
                frage2antwort1 = $('#frage2antwort1:checked').length; f.Example Value = 0
                frage2antwort2 = $('#frage2antwort2:checked').length; f.Example Value = 0
                frage2antwort3 = $('#frage2antwort3:checked').length; f.Example Value = 1

                var frage3 = document.getElementById("frage3").innerHTML;
                frage3antwort1 = $('#frage3antwort1:checked').length; f.Example Value = 1
                frage3antwort2 = $('#frage3antwort2:checked').length; f.Example Value = 0
                frage3antwort3 = $('#frage3antwort3:checked').length; f.Example Value = 0

                var frage4 = document.getElementById("frage4").innerHTML;
                frage4antwort1 = $('#frage4antwort1:checked').length; f.Example Value = 0
                frage4antwort2 = $('#frage4antwort2:checked').length; f.Example Value = 1
                frage4antwort3 = $('#frage4antwort3:checked').length; f.Example Value = 0 

                var frage5 = document.getElementById("frage5").innerHTML;
                frage5antwort1 = $('#frage5antwort1:checked').length; f.Example Value = 0
                frage5antwort2 = $('#frage5antwort2:checked').length; f.Example Value = 1
                frage5antwort3 = $('#frage5antwort3:checked').length; f.Example Value = 0

i am trying to build an array with questions and selected answer for it. nothing is right by me. as result [Question=1, Answer= 3], something like that. please help!

2
  • I don't see where you actually push values onto the answers array. Commented Sep 26, 2013 at 12:28
  • all my ideas are wrong, and its not working. i hope for some clean solutions from you... Commented Sep 26, 2013 at 12:29

1 Answer 1

1

why are you trying arrays ? you can do the same easily with objects.

please check http://www.w3schools.com/js/js_objects.asp

for Example

function question(que,ans1,ans2,ans3)
{
this.question=que;
this.answer1=ans1;
this.answer2=ans2;
this.answer3=ans3;
}

and then

var frage1=new question(document.getElementById("frage1").innerHTML, $('#frage1antwort1:checked').length,$('#frage1antwort2:checked').length,$('#frage1antwort3:checked').length);

you just need to define question object then create new objects or assign the values and grab whenever required.

This will give you clear idea Working with objects

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

5 Comments

you just need to define question object then create new objects or assign the values and grab whenever required.
thank you it works well! can i save all 5 question in one object which i can build as a result for responce??
it will be easy if you create an array of 5 question object :)
yes i did it like this: function surveyResultFull(frage1, frage2, frage3, frage4, frage5) { this.frage1 = frage1; this.frage2 = frage2; this.frage3 = frage3; this.frage4 = frage4; this.frage5 = frage5; }
and filling it here: var frage5 = new surveyResult(document.getElementById("frage5").innerHTML, $('#frage5antwort1:checked').length, $('#frage5antwort2:checked').length, $('#frage5antwort3:checked').length); var result = surveyResultFull(frage1, frage2, frage3, frage4, frage5);

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.