lundi 29 juin 2015

C#/Html Survey Quiz Logic

I had to change the tags used for question answers to 's since we wanted the entire area to be clickable. As I understand, this means that the value that we used to assign to the inputs can no longer be retrieved with Request.Form[]. So, i instead set up onclick html methods for each question that submits the questions value in the function like this:

<div id="Question1" style="display:normal;">
<p class="QuizQuestion">Question text......</p>
<p>
    <button class="QuizButton" type="button" name="Q1" value="1" onclick="ShowHide('Question1', 'Question2'), Q1Log(1);" > Answer1 Text..</button>
</p>

    <p><button class="QuizButton" type="button" name="Q1" value="2" onclick="ShowHide('Question1', 'Question2'), Q1Log(2);" >Answer2 Text.....</button>
</p>

At the bottom of my page I have the hiddent field that will contain the answer value:

My Javascript is this:

<script type="text/javascript">
function Q1log(Answer) {
        document.getElementById(Answer1) = Answer;
}
</script>

And then I try to retreive this Javascript variable when I call the results function when the submit button is pressed:

public string Results(string Answer1)
{
    if (Answer1== "1")
    {
       AnswerTally++;
    }
}

This isn't working and the tallies remain at their initial values. Can anyone suggest an improvement? The buttons need to be entirely clickable while still being able to contain the css class with the text inside of the button.

Aucun commentaire:

Enregistrer un commentaire