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
381 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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

DevOps Toolchain Recommendations

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

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem in SELECT Statement 5 83
Cold Fusion Migration 4.5 --> 10 !! 4 51
ColdFusion 10 Error 2 50
popup load of page and setting up of session 8 37
Hi, I will be creating today a basic tutorial on how we can create a Mail Custom Function and use it where ever we want. The main advantage about creating a custom function is that we can accommodate a range of arguments to pass to the Function and …
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

773 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