Need Help with inserting data in hidden field based upon radio button selection.

I have a form created with Adobe Dreamweaver Developer's Toolbox with a radio group where the user can select one of 5 selections.  Four of the answers result in a 'y' value and one results in a 'n' value for a "licensed" field.  Based upon this y or n value I want to insert the value "Contractor" or "Associate" to a  "membertype" field in my MySql database. The "membertype" field is included in the form as a hidden field.   I have made several attempts with <cfif> and IIF statements to try and set the value of the hidden field, however, I am unable to capture the value of "licensed", and the if statement always defaults to the "else" value.

I am attaching my code, without my if statement attempts, and would appreciate someone could give me the proper code to accomplish my goal.


<cfinclude template="../includes/common/KT_common.cfm">
<cfinclude template="../includes/tng/tNG.inc.cfm">
<cfscript>
// Make a transaction dispatcher instance
tNGs = Request.tNG_CreateObject("tNG_dispatcher");
tNGs.init("../");
</cfscript>
<cfscript>
// Start trigger
formValidation = Request.tNG_CreateObject("triggers.tNG_FormValidation");
formValidation.init();
tNGs.prepareValidation(formValidation);
// End trigger
</cfscript>
<cfscript>
// Make an insert transaction instance
ins_nari_company = Request.tNG_CreateObject("tNG_insert");
ins_nari_company.init("datasource");
tNGs.addTransaction(ins_nari_company);
// Register triggers
ins_nari_company.registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "KT_Insert1");
ins_nari_company.registerTrigger("BEFORE", "Trigger_Default_FormValidation", 10, formValidation);
ins_nari_company.registerTrigger("END", "Trigger_Default_Redirect", 99, "../login.cfm");
// Add columns
ins_nari_company.setTable("nari_company");
ins_nari_company.addColumn("company_name", "STRING_TYPE", "POST", "company_name");
ins_nari_company.addColumn("licensed", "STRING_TYPE", "POST", "licensed");
ins_nari_company.addColumn("membertype", "STRING_TYPE", "POST", "membertype");
ins_nari_company.setPrimaryKey("id", "NUMERIC_TYPE");
</cfscript>
<cfscript>
// Execute all the registered transactions
tNGs.executeTransactions();
</cfscript>
<cfscript>
// Get the transaction recordset
rsnari_company = tNGs.getRecordset("nari_company");
</cfscript>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href="../includes/skins/mxkollection3.css" rel="stylesheet" type="text/css" media="all" />
<script src="../includes/common/js/base.js" type="text/javascript"></script>
<script src="../includes/common/js/utility.js" type="text/javascript"></script>
<script src="../includes/skins/style.js" type="text/javascript"></script>
<cfoutput>#tNGs.displayValidationRules()#</cfoutput>
</head>
 
<body>
<cfoutput>#tNGs.getErrorMsg()#</cfoutput>
<form method="post" id="form1" action="<cfoutput>#Request.KT_escapeAttribute(Request.KT_getFullUri())#</cfoutput>">
  <table cellpadding="2" cellspacing="0" class="KT_tngtable">
    <tr>
      <td class="KT_th"><label for="company_name">Company_name:</label></td>
      <td><input type="text" name="company_name" id="company_name" value="<cfoutput>#Request.KT_escapeAttribute(rsnari_company.company_name)#</cfoutput>" size="32" />
          <cfoutput>#tNGs.displayFieldHint("company_name")#</cfoutput> <cfoutput>#tNGs.displayFieldError("nari_company", "company_name")#</cfoutput> </td>
    </tr>
    <tr>
      <td class="KT_th"><label for="licensed_1">Licensed:</label></td>
      <td><div>
        <input <cfoutput>#Iif(Request.KT_escapeAttribute(rsnari_company.licensed) EQ "y",DE("CHECKED"),DE(""))#</cfoutput> type="radio" name="licensed" id="licensed_1" value="y" />
        <label for="licensed_1">Licensed</label>
      </div>
          <div>
            <input <cfoutput>#Iif(Request.KT_escapeAttribute(rsnari_company.licensed) EQ "y",DE("CHECKED"),DE(""))#</cfoutput> type="radio" name="licensed" id="licensed_2" value="y" />
            <label for="licensed_2">Exempt < $2500</label>
          </div>
        <div>
            <input <cfoutput>#Iif(Request.KT_escapeAttribute(rsnari_company.licensed) EQ "y",DE("CHECKED"),DE(""))#</cfoutput> type="radio" name="licensed" id="licensed_3" value="y" />
            <label for="licensed_3">Exempt Specialty</label>
          </div>
        <div>
            <input <cfoutput>#Iif(Request.KT_escapeAttribute(rsnari_company.licensed) EQ "y",DE("CHECKED"),DE(""))#</cfoutput> type="radio" name="licensed" id="licensed_4" value="y" />
            <label for="licensed_4">Exempt Repair</label>
          </div>
        <div>
            <input <cfoutput>#Iif(Request.KT_escapeAttribute(rsnari_company.licensed) EQ "n",DE("CHECKED"),DE(""))#</cfoutput> type="radio" name="licensed" id="licensed_5" value="n" />
            <label for="licensed_5">Not a Contractor</label>
          </div>
        <cfoutput>#tNGs.displayFieldError("nari_company", "licensed")#</cfoutput> </td>
    </tr>
    <tr class="KT_buttons">
      <td colspan="2"><input type="submit" name="KT_Insert1" id="KT_Insert1" value="Insert record" /></td>
    </tr>
  </table>
  <input type="hidden" name="membertype" id="membertype" value="<cfoutput>#Request.KT_escapeAttribute(rsnari_company.membertype)#</cfoutput>" />
</form>
<p>&nbsp;</p>
</body>
</html>

Open in new window

edfmAsked:
Who is Participating?
 
azadisaryevConnect With a Mentor Commented:
adding an onClick event to each of your radio inputs should do the trick:

for the "y" ones add:
onClick="document.getElementById('membertype').value='Contractor';"

for the "n" one change 'Contractor' to 'Associate' in the line above.

hth
0
 
edfmAuthor Commented:
Indeed, this does work. Thank you for your help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.