?
Solved

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

Posted on 2008-11-13
2
Medium Priority
?
400 Views
Last Modified: 2013-12-16
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

0
Comment
Question by:edfm
2 Comments
 
LVL 27

Accepted Solution

by:
azadisaryev earned 2000 total points
ID: 22957587
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
 

Author Closing Comment

by:edfm
ID: 31516610
Indeed, this does work. Thank you for your help.
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

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

This guide will walk you through the essential considerations and tech stack for building scalable websites. Know how to grow your business the smart way!
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
The purpose of this video is to demonstrate how to add AdSense Ads to a WordPress Website, and how to set up WordPress to automatically place Ads in Sidebars. This will be demonstrated using a Windows 8 PC. Log into your AdSense account. : Cli…
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…
Suggested Courses
Course of the Month17 days, 8 hours left to enroll

830 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