Solved

Alert Message/onClick/JavaScript - EASY POINTS

Posted on 2001-09-14
4
263 Views
Last Modified: 2008-03-10
I need assistance with the following function.


<script language="JavaScript">
<!--
function checkFields() {
var form = document.forms[0];  
if ((form.RadialButton.value == "Yes")) {
alert("Message to display onClick.")
return false;
}
else {
return true;
}
}
// -->
</script>


<input type="radio" name="RadialButton" value="Yes" onClick="return checkFields()">


When a user clicks this radial button, I have an onClick event calling this function, which displays the message, which is what I need.  But after the user hits OK from the alert, I need the radial button to stay selected and allow them to continue through the form.  Currently, I select the radial button, get the message, hit OK, then the radial button is unselected.  If I try to select it again it does the same thing.  I know I am missing some other command to let the user pass after they have hit OK from the message, but I have been unable to figure it out.  Time is of the essence.  (points added for quick response)  Please assist.  Thank you.
0
Comment
Question by:goon55
  • 3
4 Comments
 
LVL 8

Expert Comment

by:bebonham
ID: 6482607
if ((form.RadialButton.checked)) {
0
 
LVL 8

Expert Comment

by:bebonham
ID: 6482613
sorry...

not understanding


.


<script language="JavaScript">
<!--
function checkFields() {
var form = document.forms[0];  
if ((form.RadialButton.value == "Yes")) {
alert("Message to display onClick.")
return true;
}
else {
return false;
}
}
// -->
</script>
<FORM>

<input type="radio" name="RadialButton" value="Yes" onClick="return checkFields()">
<FORM>
0
 
LVL 8

Accepted Solution

by:
bebonham earned 50 total points
ID: 6482617
but you should still used checked instead of =="YES" because even if the button is not selected, it's value is yes.

however, it doesn't matter since you only have one radio button.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 6482808
Bebonham is totally correct...

If you have two (which is standard) , use this:
<script language="JavaScript"><!--
function checkBut(theButton) {
   if (theButton.value == "Yes") { // the yes button was clicked
      alert("Message to display if yes.")
   }
   else {
      alert("Message to display if no.")
   }
}
</script>
<input type="radio" name="RadialButton" value="No" onClick="checkBut(this)">
<input type="radio" name="RadialButton" value="Yes" onClick="checkBut(this)">

but if you must have the user check to continue - use a checkbox:

<script>
function validate(theForm) {
   return theForm.disclaimer.checked;
}
</script>
<form onSubmit="return validate(this)">
<input type="checkbox" name="disclaimer" value="yes">Have you read our disclaimer and agree with it?
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now