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
380 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
  • 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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
 

Author Comment

by:LelloLello
ID: 37782511
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article  is about submitting  form through  ColdFusion.Ajax.submitForm to the action page and send a response back in JSON format which later can be decoded using ColdFusion.JSON.decode. By this way you can avoid the usual page refresh for subm…
CFGRID Custom Functionality Series -  Part 1 Hi Guys, I was once asked how it is possible to to add a hyperlink in the cfgrid and open the window to show the data. Now this is quite simple, I have to use the EXT JS library for this and I achiev…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

911 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

24 Experts available now in Live!

Get 1:1 Help Now