Solved

If I don't select yes or no into my radio button question i'm getting an error

Posted on 2012-03-28
7
387 Views
Last Modified: 2012-03-29
Please see images:
question 1 - if nothing is selected and i click yes i got a coldfusion error
question 1 - if i select a yes a textfield show, the form is working fine.
                    If i select no, the form is working fine.

So, I have a radio question 'Yes' or 'no'. Could you please advice on that error. How I can fix my code:

my form code:
------------------------
<script type="text/javascript">
function checkme(ele){
      var inputbox = document.getElementById("specify");
      if(ele.value=="Yes"){
            inputbox.style.display="block";
            var er = document.getElementById("error");
            er.style.display="none";
      }else{
            inputbox.style.display="none";
      }
}

function checksubmit(f){
      var radio = f.contactMeYes.value;
      var inputbox = f.ContactMeSpecify.value;
      if(radio=="Yes" && inputbox==""){
            var er = document.getElementById("error");
            er.style.display="inline";
            return false;
}else{
            var er = document.getElementById("error");
            er.style.display="none";
            return true;
            }
}
</script>


 <p><br><label for="strEmail"><strong><strong>1.</strong>      If your skill set is suitable to other committees, would you be willing to be contacted regarding any openings?   </label> </p>

<table border="0" cellspacing="0" cellpadding="0" width="100%" class="qtable">
<tr><td colspan="2" height="5" width="100%">

<input type="radio" name="contactMe" id="contactMeYes" value="Yes" onClick="checkme(this);"/>&nbsp;<label for="ContactMeYes">Yes</label>

<input type="radio" name="contactMe" id="contactMeNo" value="No" onClick="checkme(this);"/>No</label>

<br>
<div id="specify" style="display:none;">
<label>Please specify:
<input type="text" name="ContactMeSpecify" id="ContactMeSpecify" value="" maxlength="255" size="30" style="width: 200px;border:red 1px solid;">
</label>
</div>              

</td></tr> </table>


my Confirmation code
----------------------------------
  <cfmail from="#form.email#"
            server="mail.abc.ca"
            subject="test"
            to="jo@adc.ca"
            type="html">
                   ------------------------------------------------------------<BR>
                <B>Member ID and User ID:</B>#Form.ID_Number# - #user_id#<BR>
                <B>Your skill set is suitable to other committees:</B> #Form.ContactMe# <cfif contactMeSpecify neq "">(#FORM.ContactMeSpecify#)</cfif> <br>
             
            </cfmail>


My Error if I don't select a YES or a NO, i'm getting that error.. how i can resolve it ?

<P>An error occurred while evaluating the expression:
<P><PRE>"#form.contactMe#"
</PRE></P></P>Error near line 39, column 41.<HR><P>Error resolving parameter <B>FORM.CONTACTME</B><P><P>The specified form field cannot be found. This problem is very likely due to the fact that you have misspelled the form field name.<P><P> <p>The error occurred while processing an element with a general identifier of (CFQUERYPARAM), occupying document position (39:17) to (39:83) in the template file D:\USERS\ACTCA\HTML\MEMBERS\VOLUNTEER\CONFIRMATION_E.CFM.</p><P><P>
q1.jpg
q1ifYes-selected-textfield-wills.jpg
0
Comment
Question by:LelloLello
[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
  • 4
  • 2
7 Comments
 
LVL 8

Expert Comment

by:Ben McNelly
ID: 37777744
I would just add

checked="true"

Open in new window


to the first one
0
 
LVL 52

Expert Comment

by:_agx_
ID: 37777810
Radio buttons only exist IF they're checked. If neither button is checked the field won't exist on the action page. That's why you're getting an error.

How you handle it depends on whether it's mandatory. If so, you need to force the user to make a selection and prevent the form from submitting until they do. You can use javascript, but should re-validate on the server as well.

Not tested
        <script type="text/javascript">
              function atLeastOneWasChecked(frm) {
                   var buttons = frm.contactMe;
                   for (var i = 0; i < buttons.length; i++)  {
                          if (buttons[i].checked) {
                                return true;
                          }
                   }
                  alert('Please select yes or no');
                   return false; 
              }
        </script>
        <!--- before submitting verify one button was checked ...--->
        <form onSubmit="return atLeastOneWasChecked(this);" ....>
              ....

Open in new window

       
Otherwise, just set a default like "no", so you don't get an error when you try and use the field.

        <!--- so the field always exists ...--->
        <cfparam name="form.contactMe" default="no">    
          ... rest of action page code
0
 

Author Comment

by:LelloLello
ID: 37777973
i like it but it didn't work. the javascript is not launching...  so this message 'Please select yes or no' is not displaying...
0
Setting up LaraDock for Laravel

Learn how to set up LaraDock in a Laravel project - LaraDock gives us an easy way to run a Laravel application using Docker in a single command.

 

Author Comment

by:LelloLello
ID: 37777977
.............
</head>


        <script type="text/javascript">
              function atLeastOneWasChecked(frm) {
                   var buttons = frm.contactMe;
                   for (var i = 0; i < buttons.length; i++)  {
                          if (buttons[i].checked) {
                                return true;
                          }

                   return false; 
              }
        </script>

<script type="text/javascript">
function checkme(ele){
	var inputbox = document.getElementById("specify");
	if(ele.value=="Yes"){
		inputbox.style.display="block";
		var er = document.getElementById("error");
		er.style.display="none";
	}else{
		inputbox.style.display="none";
	}
}

function checksubmit(f){
	var radio = f.contactMeYes.value;
	var inputbox = f.ContactMeSpecify.value;
	if(radio=="Yes" && inputbox==""){
		var er = document.getElementById("error");
		er.style.display="inline";
		return false;
}else{
		var er = document.getElementById("error");
		er.style.display="none";
		return true;
		}
}
</script>


<body>

        <cfform id="form1" name="form1" onSubmit="return atLeastOneWasChecked(this);" action="confirmation_e.cfm" method="POST">

<table border="0" cellspacing="0" cellpadding="0" width="100%" class="qtable">
            <tr>
              <td colspan="2" height="5" width="100%">
           				<input type="radio" name="contactMe" id="contactMeYes" value="Yes" onClick="checkme(this);"/>Yes
							<input type="radio" name="contactMe" id="contactMeNo" value="No" onClick="checkme(this);"/>No</label>
							&nbsp;&nbsp;<br>
                            <div id="specify" style="display:none;">
<label>Please specify:
<input type="text" name="ContactMeSpecify" id="ContactMeSpecify" value="" maxlength="255" size="30" style="width: 200px;border:red 1px solid;">
</label>
</div>              
</td>
            </tr>
          </table>
   </cfform>

FYI, I have disabled this code in my confirmation.cfm.

 <!---<B>Your skill set is suitable to other committees:</B> #Form.ContactMe# <cfif contactMeSpecify neq "">(#FORM.ContactMeSpecify#)</cfif> <br>--->

So there is no error but the javascript message doesn't display this msg. 'Please select yes or no?  Why pls advice.

Open in new window

0
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 37778098
i like it but it didn't work. the javascript is not launching.


Yeah, like I mentioned it's not tested. So there may be a typo in my code or yours. I can't test any of this right now. But since you're using cfform already, why not use <cfinput>?  Then you don't need extra js functions only:

<!--- REMOVE the onSubmit="return ..." code --->
<cfform ...>
     <cfinput type="radio" name="contactMe" value="Yes"
         required="true" message="Please select Yes or No"  .../>Yes
     <cfinput type="radio" name="contactMe" value="No" ... />No
                              
</cfform>
0
 

Author Comment

by:LelloLello
ID: 37778177
WOW that was the msg i'm missing !!! Genius :)
message="Please select Yes or No"
0

Featured Post

Command Line Tips and Tricks

The command line is a powerful tool at the disposal of every Linux user. Although Linux distros come with beautiful user interfaces, it's worthwhile to learn the command line because it allows you to do a number of things that you otherwise cannot do from the GUI.  

Question has a verified solution.

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

PROBLEM: How to add your own buttons to the bottom toolbar with paging info ( result count ). While creating a cfgrid, I ran into an issue where I wanted to embed my own custom buttons where the default ones ( insert / delete / etc… ) are for aes…
Today, I was working on some optimization and spam-stopping techniques when I encountered Ben Nadel's post to reduce spam feature using Math (http://www.bennadel.com/blog/197-How-I-Stop-Spammers-On-My-ColdFusion-Blog.htm). While this method is not o…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

615 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