Add client script for radio type input (additional implementation JS to disable onclick event mentality code) _ form Effects

Source: Internet
Author: User
Tags php and
The following example shows that the result is no overload display submission.


when the user selects an option, a function is called "getvote ()" execution. The "onclick" event that is raised by this feature


Copy Code code as follows:

<script type= "Text/javascript" >
function getvote (int)
{
if (window). XMLHttpRequest)
{//code for ie7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest ();
}
Else
{//code for IE6, IE5
xmlhttp=new activexobject ("Microsoft.XMLHTTP");
}
Xmlhttp.onreadystatechange=function ()
{
if (xmlhttp.readystate==4 && xmlhttp.status==200)
{
document.getElementById ("poll"). Innerhtml=xmlhttp.responsetext;
}
}
Xmlhttp.open ("Get", "poll_vote.php?vote=" +int,true);
Xmlhttp.send ();
}
</script>
<body>

<div id= "poll" >
<form>
Yes:
<input type= "Radio" name= "vote" value= "0" onc lick= "Getvote (this.value)"/>
<br/>no:
<input TypE= "Radio" name= "Vote" value= "1" onclick= "Getvote (this.value)"/>
</form>
</div>
</body& Gt






the Getvote () function does the following:


Create an XMLHttpRequest object


Create the function to being executed the server response is ready


Send the request off to a file on the server


Notice that a parameter (vote) are added to the URL (with the value of the Yes or no option)


to determine if the control's disabled property is true, return false, implement the disable Radio onclick event, and enable it again


method One: (At the same time disable, re-enable features, only for button text type input, the DIV can not disable its OnClick event)


&lt;input type= "button" value= "A button. Click me to the Alert box. "onclick=" alert (' I am clicked. '); "id= cmd1"/&gt;


&lt;br/&gt;


&lt;input type= "button" value= "Click Me to disable" "Onclick=" document.getElementById (' cmd1 '). disabled=true; "/&gt;


&lt;br/&gt;


method Two, three: (Implement the Remove Radio onclick event, need to re-register the event again, you can disable Div's onclick event)


&lt;input type= "button" value= "Click me to disable the onclick event on the" "Onclick=" document.getElementById (' cm D1 '). Onclick=function () {}; "/&gt;





&lt;br/&gt;


III:


&lt;input type= "button" value= "Click me to disable the onclick event on the" "Onclick=" document.getelementbyi D (' cmd1 '). Onclick=null; "/&gt;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.