Solved

Alert Message/onClick/JavaScript - EASY POINTS

Posted on 2001-09-14
4
275 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
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…

738 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