coldfusion - Radio button not checked breaks page but works if checked -


i have simple form i'm trying pass data on action page has email sends data put form.

on form page. have text field , 2 radio buttons.

my text field works if don't put data it. however, on radio buttons page works if check doesnt work if don't check @ results in page breaking i'm not sure i'm doing wrong? want page process default "no" if didn't check either radio buttons. have validate or something?

here code.

<cfparam name="form.firstname" default=""> <cfparam name = "form.optradio1" default="no">  <form action="test.cfm" method="post">   <label for="firstname"></label>   <input type="text" name="firstname">   <input type="radio" name="optradio1" value="male" <cfif form.optradio1 eq "yes">checked</cfif>> </form> 

that's how radio , checkbox inputs work in html. if not checked, not submitted on form submit.

to determine if radio input checked, can use
structkeyexists(form, <name of input, string>) in
structkeyexists(form, "optradio1").

<cfparam name="form.firstname" default="">  <form action="test.cfm" method="post">   <label for="firstname"></label>   <input type="text" name="firstname">   <input type="radio" name="optradio1" value="male" <cfif structkeyexists(form, "optradio1")>checked</cfif>> </form> 

assuming have 2 radio inputs:

<cfparam name="form.firstname" default="">  <form action="test.cfm" method="post">   <label for="firstname"></label>   <input type="text" name="firstname">   <input type="radio" name="optradio1" value="male" <cfif structkeyexists(form, "optradio1") , form.optradio1 eq "male">checked</cfif>>   <input type="radio" name="optradio1" value="female" <cfif structkeyexists(form, "optradio1") , form.optradio1 eq "female">checked</cfif>> </form> 

your initial code doesn't work because:

  • if checked, form.optradio1 equal male
  • if not checked, form.optradio1 defaulted no because of
    <cfparam name = "form.optradio1" default="no">

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -