SoFunction
Updated on 2025-02-28

Add client scripts for radio-type INPUT (additional implementation of JS to disable onClick event idea code)

The following example will show that the result is no overloaded display commit.
When the user selects an option above, a function is called "getVote()" to execute. The function triggers the "OnClick" event
Copy the codeThe code is as follows:

<html>
<head>
<script type="text/javascript">
function getVote(int)
{
if ()
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("");
}
=function()
{
if (==4 && ==200)
{
("poll").innerHTML=;
}
}
("GET","poll_vote.php?vote="+int,true);
();
}
</script>
</head>
<body>

<div >
<h3>Do you like PHP and AJAX so far?</h3>
<form>
Yes:
<input type="radio" name="vote"value="0" onclick="getVote()" />
<br />No:
<input type="radio" name="vote"value="1" onclick="getVote()" />
</form>
</div>
</body>
</html>


The getVote() function does the following:
Create an XMLHttpRequest object
Create the function to be executed when the server response is ready
Send the request off to a file on the server
Notice that a parameter (vote) is added to the URL (with the value of the yes or no option)
Determine whether the disabled property of the control is true, if so, return false; implement the onclick event of radio and enable it again
Method 1: (At the same time, the disable and re-enable function can only be used for button text type INPUT, and the onclick event cannot be disabled for div)
<input type="button" value="A button. Click me to see the alert box." onclick="alert('I am clicked.');" />
<br/>
<input type="button" value="Click me to disable the first button" onclick="('cmd1').disabled=true;" />
<br/>
Method 2 and 3: (Implement the onclick event that removes radio, and re-register the event again, and the onclick event of div can be disabled)
<input type="button" value="Click me to disable the onclick event on first button" onclick="('cmd1').onclick=function(){};" />

<br/>
three:
<input type="button" value="Click me to disable the onclick event on first button" onclick="('cmd1').onclick=null;" />