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
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
382 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
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

790 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