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
379 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

708 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

18 Experts available now in Live!

Get 1:1 Help Now