Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I didn't find an answer here (maybe because my knowledge in JS is very limited), so I decided to ask the question myself: How can I execute my javascript after a certain event? I have a form and I want the JS to run after the last radio is selected but before submitting the form.

<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<form id="myform">
   //various fields
</form>


<script type="text/javascript">

 function myfunction() {}


</script>
</body>
</html>

I managed the function to run when loading the website and after the last field was filled/radio was checked, but i want it to run ONLY when the last radio was checked.

Thx for everyone to help me


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
112 views
Welcome To Ask or Share your Answers For Others

1 Answer

Try: onclick=“myfunction()” For example if your code is <input type=“checkbox” onclick=“myfunction()”> Then it might run something like this:

function myfunction() {
  alert("Box Checked!")
  //Put whatever you want in here
 }
function myfunction2() {
  alert("Thank you for submitting this form!")
  //Put whatever you want in here as well
 }
<!Doctype html>
<html>
<p>Check this box!</p>
<input type="checkbox" onclick="myfunction()">Check me!</input>
<!-- notice the onclick function here -->
<br>
</html>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...