Jump to content

array question


angel777

Recommended Posts

i am afraid i do not get u .. newbie here..

my code is below.. my idea is instead of display all question and counting the total .. i want to split each question by clicking on the next button.. after complete the question.. sum up the total ..  how should i do that  :-[

 

script type="text/javascript">
function checkTotal() {
    var total = document.listForm.total;
    var choice = document.listForm.choice;
    var choice1 = document.listForm.choice1;
    var sum = 0;

    for (i=0;i<choice.length;i++) {
        if (choice[i].checked)
            sum = sum + parseInt(choice[i].value);
    }

    for (i=0;i<choice1.length;i++) {
        if (choice1[i].checked)
            sum = sum + parseInt(choice1[i].value);
    }

   // total.value = sum;
document.listForm.total.value = sum;
}

</script>




</head>

<body>

<form name="listForm">

<p>2) Do you  feel more self-confident than usual?</p>
<ul>
<Input class="checkbox" type="checkbox" name="choice" value="1"
onclick="checkTotal()">Yes <br>
<Input class="checkbox" type="checkbox" name="choice" value="0"
onclick="checkTotal()">No <br>
</ul>

<p>2) Do you  feel happy?</p>
<ul>
<Input class="checkbox" type="checkbox" name="choice1" value="1"
onclick="checkTotal()">Yes <br>
<Input class="checkbox" type="checkbox" name="choice1" value="0"
onclick="checkTotal()">No <br>
</ul>

Total: <input type="text" size="2" name="total" value="0"/>

Link to comment
Share on other sites

sorry man this is Java script not php you post in <a href="http://www.phpfreaks.com/forums/index.php/board,6.0.html">JS section</a>

 

maybe you can do this.. once the user click check your hidden fields (put a hidden field that will contain the number of pages or maybe the page it display)  then in you function look at that field and use that as one of the condition to get the page you're about to display

and note you have to increment or decrement the value of that hidden field so you know what page you're going once next is clicked

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.