Skip to main content
Known Participant
February 1, 2010
Question

dynamic radio button issues.

  • February 1, 2010
  • 1 reply
  • 1495 views

Hello;

I changed around the way I do a contact form from one page loading onto another to just one page. I had my radio buttons working the 2 page way, but now, it throws an error and says that the TYPE is undefined in the form. The type is the name of my group of radio buttons. Here is what I'm doing, can someone help me fix this so a form will remember if it has to be reloaded what radio button you chose?

My code:

<cfform action="#cgi.script_name#" method="post">

<cfif form.type EQ 'male'>

<input name="type" type="radio" onClick="setVisibility('sub3', 'inline');setVisibility('sub4','none');setVisibility('sub5','none');" value='male' checked="checked"/>

<cfelse>

<input name="type" type="radio" onClick="setVisibility('sub3', 'inline');setVisibility('sub4','none');setVisibility('sub5','none');" value='male'/>

</cfif>

<cfif form.type EQ 'female'>

<input type="radio" name="type" value='female' onClick="setVisibility('sub3', 'none');setVisibility('sub4','inline');setVisibility('sub5', 'none');" checked="checked"/>

<cfelse>

<input type="radio" name="type" value='female' onClick="setVisibility('sub3', 'none');setVisibility('sub4','inline');setVisibility('sub5', 'none');"/>

</cfif>

<cfif form.type EQ 'child'>

<input type="radio" name="type" value='child' onClick="setVisibility('sub3', 'none');setVisibility('sub4','none');setVisibility('sub5', 'inline');" checked="checked"/>

<cfelse>

<input type="radio" name="type" value='child' onClick="setVisibility('sub3', 'none');setVisibility('sub4','none');setVisibility('sub5', 'inline');"/>

</cfif>

those are the 3, I need this form to remember your choice, they control parts of the form. The if statement is throwing the error, this is the error:

Element TYPE is undefined in FORM.

  The error occurred in C:\quoteReq.cfm: line 282
Called from C:\Websites\187914kg3\quoteReq.cfm: line 276
Called from C:\Websites\187914kg3\quoteReq.cfm: line 275
Called from C:\Websites\187914kg3\quoteReq.cfm: line 260
Called from C:\Websites\187914kg3\quoteReq.cfm: line 1

280 :                 <span class="contactText">Select the type of project to get a quote.</span><br>
281 :                 <br>
282 :                 <input name="type" type="radio" id="type" onClick="setVisibility('sub3', 'inline');setVisibility('sub4','none');setVisibility('sub5','none');" value='male' <cfif form.type EQ 'male'>checked="checked"</cfif>/>
283 :                 <span class="contactText">Magnets</span>
284 :                 <input type="radio" name="type" id="type" value='female' onClick="setVisibility('sub3', 'none');setVisibility('sub4','inline');setVisibility('sub5', 'none');" <cfif form.type EQ 'female'>checked="checked"</cfif>/>    

Can anyone help me fix this please?

    This topic has been closed for replies.

    1 reply

    Owainnorth
    Inspiring
    February 1, 2010

    Yup, it's a simple one this.

    In your code you're doing <cfif FORM.type EQ ... >, but until the form has been submitted there's no such variable as TYPE in the FORM scope, as it says.

    Therefore use the CFPARAM tag at the top of your page:

    <cfparam name="FORM.type" default="" />

    Which simply sets a default value for a variable. That should sort your problems.

    O.

    Known Participant
    February 1, 2010

    That worked on the error. It's loading the form now. But now my radio buttons don't change the

    part of the form they're supposed too. They don't do anything.

    I had to set my default to male, because when it loads, and there is no default, part of the form doesn't show until you chose one of the radio buttons. Is there a better way to do this? What I need it to do it this, male has to be default. when you click on a radio button, it swaps out part of the form for what you need it to send. When they hit submit, lets say they forgot their state, then when the form submits, I need it to remember wich radio button you clicked so it doesn't load the wrong part.

    Right now, it just loads male and won't load anything else.

    Inspiring
    February 1, 2010

    instead of cfparam, use if/else logic on whether or not the form has been submitted.  Either IsDefined() or StructKeyExists() can be used to check.