Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
here is the code for page that increments counter whenever Algeria is selected would want the value of counter to carry on to next page and increment if correct radio button is pressed


<html>
    <head>
        <title>Javascript Counts</title>          
        <script type="text/javascript"> 
            
            var counter = 4;
            document.write("The counter is " + counter)
            function vals()      
            {                    
                   
            var radios = document.getElementsByName("rbnNumber");               
            for (var i = 0; i < radios.length; i++) 
            {                            
            var r = radios[i];             
            if (r.value == "1" && r.checked) 
            {               
            document.getElementById('boldStuff').innerHTML = 'You selected Tasmania';
            }    
            if (r.value == "2" && r.checked) 
            {               
            document.getElementById('boldStuff').innerHTML = 'You selected Nicaragua';
            }  
             if (r.value == "3" && r.checked) 
            {               
            document.getElementById('boldStuff').innerHTML = 'You selected Tunisia';
            document.getElementById('Cool').innerHTML = 'Your score is now '+counter; 
            }    
            if (r.value == "4" && r.checked) 
            {      
            counter++
            document.getElementById('boldStuff').innerHTML = 'You selected Algeria  ';
            document.getElementById('Cool').innerHTML = 'You selected Algeria  ';
            document.getElementById('Cool').innerHTML = 'Your score is now '+counter; 
            } 
        }
    }
       </script>
    </head>
    <body>
        <table align = "center">
                        <tr>
                            <td>
                        <a href = "some.html">Previous 
                            </td> 
                            <td>
                        What is the Capital of France  
                            </td> 
                            <td>
                        <a href = "JsCountsA.html">Next  
                            </td> 
                        </tr>                     
                </table>    
                <table align = "center">                
                        <tr> 
                        <td>
                        <input type="radio" name="rbnNumber" value="1" />Tasmania<br/>                    
                        </td>                                 
                        </tr>
                        <tr>
                        <td>
                        <input type="radio" name="rbnNumber" value="2" /> Nicaragua<br/>
                        </td>                    
                        </tr>
                        <tr>
                        <td>
                        <input type="radio" name="rbnNumber" value="3" /> Tunisia<br/>
                        </td>                                                    
                        </tr>
                        <tr>
                        <td>
                        <input type="radio" name="rbnNumber" value="4" /> Algeria<br/>
                        </td>                                                    
                        </tr>                                  
                </table>                 
                <table align = "center">
                        <tr>
                        <td align="center">
                       <input type="button" id="btnGetValue"  onclick="vals()" Value="Get Value" />                                                    
                       <p></p>   
                        </td> 
                        </tr>     
                        <tr>       
                             "boldStuff">
                             ^__b id="Cool">dude                             
                        </tr>
                </table>               
    </body>
</html>


What I have tried:

tried using javascript frames object so that different html is loaded on different frames the pages on different frames are counter.html and radio.html whenever correct radio is pressed counter.html is incremented and next button loads another page on radio.html
Posted
Updated 6-Jan-18 0:27am
Comments
ZurdoDev 5-Jan-18 13:36pm    
So, pass the value to the next page. What is the question?
j snooze 5-Jan-18 17:07pm    
either set a form value and post the form to the next page or pass the value as a querystring. your choice.
four systems 6-Jan-18 3:49am    
would there be a need for form handler cause what would handle the form would it be server side code like in java or cgi or could use html storage

1 solution

<form method="post">
<input type="date" name="date[]" />
<input type="text" name="versus[]" />
<input type="radio" name="ha[0]" value="home" checked="checked" />
<input type="radio" name="ha[0]" value="away" />
<br />
<input type="date" name="date[]" />
<input type="text" name="versus[]" />
<input type="radio" name="ha[1]" value="home" checked="checked" />
<input type="radio" name="ha[1]" value="away" />
<br />
<input type="date" name="date[]" />
<input type="text" name="versus[]" />
<input type="radio" name="ha[2]"  value="home" checked="checked" />
<input type="radio" name="ha[2]" value="away" />
<input type="submit" value="go" name="sub_it" />
</form>
 
Share this answer
 
Comments
four systems 6-Jan-18 9:28am    
cool but where would you view the value of selected input types wouldn't you need a form handler

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900