...

View Full Version : Complicated Survey loop



cris232
07-23-2012, 03:58 PM
http://i1142.photobucket.com/albums/n609/crislevy232/Capture.jpg

These radios have the same name so you can only select one If you select GF/BF and click submit it will alert "You have chose GF/BF 1 out 1 votes"http://i1142.photobucket.com/albums/n609/crislevy232/Capture-1.jpg
and if you click submit again with GF/BF still selected it will alert You chose GF/BF 2 out of 2 total votes. and if you submit GF/BF 5 times it will alert You selected GF/BF 5 out of 5 votes
http://i1142.photobucket.com/albums/n609/crislevy232/Capture2.jpg
Now if you click Pet and click submit it will alert: You chose Pet 1 out of 6 votes
http://i1142.photobucket.com/albums/n609/crislevy232/Capture3.jpg
Now if Pet is still selected and you click submit it will alert: You chose Pet 2 out of 7 votes
http://i1142.photobucket.com/albums/n609/crislevy232/Capture4.jpg
Now if you select back to GF/BF and click submit it will alert: You chose 6 out of 8 votes
http://i1142.photobucket.com/albums/n609/crislevy232/Capture5.jpg
When clicked Show results, It will display on how many times you voted a choice
http://i1142.photobucket.com/albums/n609/crislevy232/SHOWW.jpg
Ex:
GF/BF=1 vote
MAMA/PAPA=2votes
etc
basically a survey/voting system

cris232
07-23-2012, 04:01 PM
<html>
<head><title>ACTIVITY</title></head>
<body>
<h3>LOOPING AND POLL</h3>
<form name="super">
<input type="radio" name="poll" value="GF/BF">GF/BF <br>

<input type="radio" name="poll" value="MAMA/PAPA">MAMA/PAPA <br>

<input type="radio" name="poll" value="PET">PET <br>

<input type="radio" name="poll" value="ME">ME <br>

<input type="radio" name="poll" value="***">*** <br>
</form>
<button type="button" onclick="fxn()">Submit</button> <br>
<button type="button" onclick="fxn2()">Show results</button>
<script type="text/javascript">
var sum=1;

function fxn()
{
var b,a,c;

for(x=0;x<5;x++)
{
a=document.super.poll[x].checked;

if(a==true)
{
b=document.super.poll[x].value;
}

}
alert("You selected: " + b +" "+ sum +" Times.");
sum=sum+1;
}
</script>

</body>
</html>

basically the only thing i got

jmrker
07-23-2012, 05:12 PM
Your description on post #1 and your code of post #2 do not match.

Also you have not shown the function fxn2.

What is it that you are trying to do again?

cris232
07-23-2012, 05:32 PM
<Edited>

cris232
07-23-2012, 05:35 PM
Your description on post #1 and your code of post #2 do not match.

Also you have not shown the function fxn2.

What is it that you are trying to do again?

i Updated my 2nd code , im missing the total votes

Old Pedant
07-23-2012, 09:25 PM
But what HAPPENS to the votes????

You aren't sending them to any server, so they are just floating in the user's browser, unseen by anyone else.

WolfShade
07-23-2012, 09:28 PM
It's most likely for a class, -OR- the OP could be just experimenting, learning what can and cannot be done in JS. Just a thought. My assumption could be incorrect.

cris232
07-24-2012, 05:18 AM
It's most likely for a class, -OR- the OP could be just experimenting, learning what can and cannot be done in JS. Just a thought. My assumption could be incorrect.

Wel, you're right on both of them I have one like on my class and im just experimenting on Javascript since im new

cris232
07-24-2012, 02:22 PM
But what HAPPENS to the votes????

You aren't sending them to any server, so they are just floating in the user's browser, unseen by anyone else.

The votes only get alerted and looped. This is where the Show Results come in.
As said before
It will display on how many times you voted a choice
http://i1142.photobucket.com/albums/n609/crislevy232/SHOWW.jpg

jmrker
07-24-2012, 03:45 PM
It is better to show the code which creates the output you get
than to show a picture of what you desire as the outcome.

Place you code between [ code] and [ /code] tags (without the spaces)
to make it easier for forum viewers see your attempts.



<html>
<head>
<title>ACTIVITY</title>
</head>
<body>
<h3>LOOPING AND POLL</h3>
<form name="super" action="" method="post" onsubmit="return false">
<input type="radio" name="poll" onclick="addTo(0)" value="GF/BF">GF/BF <br>
<input type="radio" name="poll" onclick="addTo(1)" value="MAMA/PAPA">MAMA/PAPA <br>
<input type="radio" name="poll" onclick="addTo(2)" value="PET">PET <br>
<input type="radio" name="poll" onclick="addTo(3)" value="ME">ME <br>
<input type="radio" name="poll" onclick="addTo(4)" value="***">*** <br>
<button type="button" onclick="fxn()">Show results</button>
</form>

<script type="text/javascript">
var sums=[0,0,0,0,0];
var total = 0;
function addTo(p) {
sums[p]++; total++;
a=document.super.poll[p];
alert("You selected: " + a.value +" "+ sums[p] +" times out of "+total+" times.");
}
function fxn() {
var a;
var str = '';
for(x=0;x<sums.length;x++) {
a=document.super.poll[x];
if(sums[x] != 0) { str += sums[x]+' : '+a.value+' times.\n'; }
}
alert(str + '\n\n' + total + ' : Total clicks');
}
</script>

</body>
</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum