Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New Coder
    Join Date
    Jul 2012
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Complicated Survey loop



    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"
    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

    Now if you click Pet and click submit it will alert: You chose Pet 1 out of 6 votes

    Now if Pet is still selected and you click submit it will alert: You chose Pet 2 out of 7 votes

    Now if you select back to GF/BF and click submit it will alert: You chose 6 out of 8 votes

    When clicked Show results, It will display on how many times you voted a choice

    Ex:
    GF/BF=1 vote
    MAMA/PAPA=2votes
    etc
    basically a survey/voting system
    Last edited by cris232; 07-24-2012 at 12:57 PM.

  • #2
    New Coder
    Join Date
    Jul 2012
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Code:
    <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
    Last edited by cris232; 07-23-2012 at 06:54 PM.

  • #3
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,148
    Thanks
    39
    Thanked 506 Times in 500 Posts

    Question

    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?

  • #4
    New Coder
    Join Date
    Jul 2012
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts
    <Edited>
    Last edited by cris232; 07-24-2012 at 12:57 PM.

  • #5
    New Coder
    Join Date
    Jul 2012
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by jmrker View Post
    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

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,675
    Thanks
    80
    Thanked 4,644 Times in 4,606 Posts
    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.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #7
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    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.
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #8
    New Coder
    Join Date
    Jul 2012
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by WolfShade View Post
    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

  • #9
    New Coder
    Join Date
    Jul 2012
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Old Pedant View Post
    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
    Quote Originally Posted by cris232 View Post
    It will display on how many times you voted a choice

  • #10
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,148
    Thanks
    39
    Thanked 506 Times in 500 Posts

    Lightbulb

    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.

    Code:
    <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>

  • Users who have thanked jmrker for this post:

    cris232 (07-24-2012)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •