How can I create JS and HTML codes that would alert the value of a radio button (that was clicked) and at the same time,
the number on how many times you'd clicked it.
I've searched and the internet and found out two codes that 'may' help me.
1st - alerting radio buttons
<html>
<head>
<script type="text/javascript">
function GetSelectedItem()
{
var chosen=""
var i;
var len = document.f1.r1.length;
for (i=0;i<len;i++)
{
if (document.f1.r1[i].checked)
{
chosen = document.f1.r1[i].value
}
}
if (chosen == "")
{
alert("No chosen radio");
}
else
{
alert(chosen)
}
}
</script>
</head>
<body>
<h1>This test will count how many times you clicked each button</h1>
<form name="f1">
<input type="radio" name="r1" value="You clicked A">A
<input type="radio" name="r1" value="You clicked B">B
<input type="radio" name="r1" value="You clicked C">C
<input type="radio" name="r1" value="You clicked D">D
</form>
<button type="button" name="akosibuton" onclick="GetSelectedItem()"/>Count kung pila
</html>
2nd - clicks counter
<!--
The tutorial explains the simple Javascript function of counting the
number of times the button has been clicked.
-->
<html>
<head>
<title> Count the Number of Button Clicks </title>
<script language="Javascript" type="text/javascript">
var noOfClicks = 0; // Used to count the number of Clicks.
function button_click()
{
noOfClicks++; // On click of the button the value is incremented.
// The below line changes the text written on the button to display the number
// of times the button has been clicked.
window.document.ButtonForm.myButton.value="Clicked " + noOfClicks + " times";
}
</script>
<body>
<form name="ButtonForm">
<p> Click the Button Below </p>
<!--
A simple page with just a button is displayed and on the click of the button
the text on the button changes to let the user know how many times the button has
been clicked.
-->
<input type="button" name= "myButton" value="Click Me" onclick="button_click()">
</form>
</body>
</head>
</html>
So I've been thinking that If I'll be able to combine the two codes, I just might get the answer to my problem. Now my question is, how to?

New Topic/Question
Reply


MultiQuote






|