Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 307
  • Last Modified:

Alert Message/onClick/JavaScript - EASY POINTS

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
goon55
Asked:
goon55
  • 3
1 Solution
 
bebonhamCommented:
if ((form.RadialButton.checked)) {
0
 
bebonhamCommented:
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
 
bebonhamCommented:
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
 
Michel PlungjanIT ExpertCommented:
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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now