Available Budget  
Center Id
 


Employee # Name Position Hire Date Salary Increase % of Change
#empnum# #name# #post# #dateformat(rehiredate,"mm/dd/yyyy")# #dollarformat(salary)#
 
#empnum# #name# #post# #dateformat(rehiredate,"mm/dd/yyyy")# #dollarformat(salary)#
 
Total
     


Apply % across all employees
Percentage   
%    
             
Divide Budget across all employees
       

 = not eligable
 
[allowsmilie] => 1 [showsignature] => 0 [ipaddress] => [iconid] => 0 [visible] => 1 [attach] => 0 [infraction] => 0 [reportthreadid] => 0 [isusenetpost] => 1 [msgid] => [ref] => [htmlstate] => on_nl2br [postusername] => StokeyTCI [ip] => webforumsuser@m [isdeleted] => 0 [usergroupid] => [membergroupids] => [displaygroupid] => [password] => [passworddate] => [email] => [styleid] => [parentemail] => [homepage] => [icq] => [aim] => [yahoo] => [msn] => [skype] => [showvbcode] => [showbirthday] => [usertitle] => [customtitle] => [joindate] => [daysprune] => [lastvisit] => [lastactivity] => [lastpost] => [lastpostid] => [posts] => [reputation] => [reputationlevelid] => [timezoneoffset] => [pmpopup] => [avatarid] => [avatarrevision] => [profilepicrevision] => [sigpicrevision] => [options] => [akvbghsfs_optionsfield] => [birthday] => [birthday_search] => [maxposts] => [startofweek] => [referrerid] => [languageid] => [emailstamp] => [threadedmode] => [autosubscribe] => [pmtotal] => [pmunread] => [salt] => [ipoints] => [infractions] => [warnings] => [infractiongroupids] => [infractiongroupid] => [adminoptions] => [profilevisits] => [friendcount] => [friendreqcount] => [vmunreadcount] => [vmmoderatedcount] => [socgroupinvitecount] => [socgroupreqcount] => [pcunreadcount] => [pcmoderatedcount] => [gmmoderatedcount] => [assetposthash] => [fbuserid] => [fbjoindate] => [fbname] => [logintype] => [fbaccesstoken] => [newrepcount] => [vbseo_likes_in] => [vbseo_likes_out] => [vbseo_likes_unread] => [temp] => [field1] => [field2] => [field3] => [field4] => [field5] => [subfolders] => [pmfolders] => [buddylist] => [ignorelist] => [signature] => [searchprefs] => [rank] => [icontitle] => [iconpath] => [avatarpath] => [hascustomavatar] => 0 [avatardateline] => [avwidth] => [avheight] => [edit_userid] => [edit_username] => [edit_dateline] => [edit_reason] => [hashistory] => [pagetext_html] => [hasimages] => [signatureparsed] => [sighasimages] => [sigpic] => [sigpicdateline] => [sigpicwidth] => [sigpicheight] => [postcount] => 14 [islastshown] => [isfirstshown] => [attachments] => [allattachments] => ) --> dynamically name text field - Coldfusion - Advanced Techniques

dynamically name text field - Coldfusion - Advanced Techniques

K here we go again I have a form, that gets a list of users and outputs there names, and salaries, with every user there is a text field to apply an amount to there salary, once they input an amount I need to do a reload and subtract the amount from the available budget I named the text field like so (input name="#empnum#increase" type="text" size="5") empnum being the result from a query that runs when the page loads Now how do I check to see if the field is defined? I tried (cfif isdefined("form.#empnum#increase") but it tells me that ...

  1. #1

    Default dynamically name text field

    K here we go again

    I have a form, that gets a list of users and outputs there names, and
    salaries, with every user there is a text field to apply an amount to there
    salary, once they input an amount I need to do a reload and subtract the amount
    from the available budget

    I named the text field like so
    (input name="#empnum#increase" type="text" size="5")

    empnum being the result from a query that runs when the page loads

    Now how do I check to see if the field is defined?

    I tried
    (cfif isdefined("form.#empnum#increase")
    but it tells me that variable empnum is undefined

    I have to see if the text field is defined so that I can subtract it form the
    budget
    which brings another question about the syntax

    lol any help would be appreciated

    O and for what im assuming will be the first question to me, i'm dynamically
    naming the text field so 1 I can do the subtraction, and 2 so I can imput the
    results into sql.


    StokeyTCI Guest

  2. #2

    Default Re: dynamically name text field

    empnum is undefined because you need to re-run the query again on your landing
    page.

    You're probably using something like:

    <form action="index.cfm" method="post">
    <cfoutput query="GETEMPLOYEES">
    #EMPLOYEENAME# <input type="text" name="#EMPNUM#INCREASE" size="5"><BR>
    </cfoutput>
    <input type="submit" name="submit" value="submit">
    </form>

    You'll need to run the GETEMPLOYEES query again on your landing page. Using
    ISDEFINED won't work because it will return TRUE even if the text field is
    blank. You need to evaluate the variable using
    EVALUATE(FORM.'#EMPNUM#INCREASE').

    Example:
    <cfoutput query="GETEMPLOYEES">
    <cfif NOT EVALUATE('FORM.#EMPNUM#INCREASE') IS "">
    <insert your budget subtraction code here>
    </cfif>
    </cfoutput>

    JC

    J.C. Guest

  3. #3

    Default Re: dynamically name text field

    <cfoutput query="getemp">
    <cfif NOT EVALUATE('FORM.#EMPNUM#INCREASE') IS "">
    <input name="text" type="text" disabled size="10" value="defined"></td>
    <cfelse>
    <input name="text" type="text" disabled size="10"
    value="#dollarformat(getbudg.budget)#"></td>
    </cfif>
    </cfoutput>

    this gives me error element 125increase is undefined in form

    StokeyTCI Guest

  4. #4

    Default Re: dynamically name text field

    Can you post all the code?

    It almost seems like your FORM tag is using a GET method, rather than a POST method.
    J.C. Guest

  5. #5

    Default Re: dynamically name text field

    [url]http://www.tirecenters.com/test/payrollcalc/main.cfm[/url]

    I set up a test link to help me explain whats up


    StokeyTCI Guest

  6. #6

    Default Re: dynamically name text field

    <form action="inputtosql.cfm" method="post">
    <table width="100%" border="0" cellpadding="0" cellspacing="0">
    <tr class="style2">
    <td width="33%">Available Budget </td>
    <td width="33%">&nbsp;</td>
    <td>
    <div align="right">Center Id </div></td>
    </tr>
    <tr class="style2">
    <td width="33%">
    <cfoutput query="getemp">
    <cfif NOT EVALUATE('FORM.#EMPNUM#INCREASE') IS "">
    <input name="text" type="text" disabled size="10" value="defined">
    <cfelse>
    <input name="text" type="text" disabled size="10"
    value="#dollarformat(getbudg.budget)#">
    </cfif>
    </cfoutput>
    </td>

    <td width="33%">&nbsp;</td>
    <td>
    <div align="right">
    <input type="text" value="<cfoutput>#form.storenum#</cfoutput>"
    size="5" disabled>
    </div></td>
    </tr>
    </table>

    <br>
    <br>

    <table width="100%" border="1" cellpadding="2" cellspacing="0"
    bordercolor="#000000">
    <tr class="style2">
    <td width="12%">Employee # </td>
    <td width="18%">Name</td>
    <td width="13%">Position</td>
    <td width="16%">Hire Date </td>
    <td width="12%">Salary</td>
    <td width="14%">Increase</td>
    <td width="15%">% of Change </td>

    </tr>
    <cfoutput query="getemp">
    <cfif #hireyear# lt #dateformat(now(),"yyyy")#>
    <tr>
    <td><span class="style7">#empnum#</span></td>
    <td><span class="style7">#name#</span></td>
    <td><span class="style7">#post#</span></td>
    <td><span
    class="style7">#dateformat(rehiredate,"mm/dd/yyyy")#</span></td>
    <td><span class="style7">#dollarformat(salary)#</span></td>
    <td><div align="center">
    <input name="#empnum#increase" type="text" size="5">
    </div></td>
    <td>&nbsp;</td>
    </tr>
    <cfelse>
    <tr>
    <td><span class="style8">#empnum#</span></td>
    <td><span class="style8">#name#</span></td>
    <td><span class="style8">#post#</span></td>
    <td><span
    class="style8">#dateformat(rehiredate,"mm/dd/yyyy")#</span></td>
    <td><span class="style8">#dollarformat(salary)#</span></td>
    <td><div align="center">
    <input name="#empnum#increase" type="text" size="5" disabled>
    </div></td>
    <td>&nbsp;</td>
    </tr>
    </cfif>
    </cfoutput>

    <tr>
    <td colspan="4"><div align="right" class="style2">Total</div></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>

    </tr>
    </table>
    <br>
    <br>
    <table width="100%" border="0" cellpadding="0" cellspacing="0">
    <tr>
    <td colspan="2" class="style2"><div align="right">Apply % across all
    employees </div></td>
    <td width="18%" class="style2">
    <div align="left">
    <input type="checkbox" name="checkbox" value="checkbox">
    </div></td><td width="20%" class="style2"><div
    align="right">Percentage&nbsp;&nbsp;&nbsp;</div></td>
    <td width="23%" class="style2"><input name="textfield" type="text"
    size="3">
    %</td>
    <td width="3%" class="style2">&nbsp;</td>
    <td width="5%" class="style2">&nbsp;</td>
    </tr>
    <tr>
    <td width="14%">&nbsp;</td>
    <td width="17%">&nbsp;</td>
    <td width="18%">&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td colspan="2" class="style2"><div align="right">Divide Budget across all
    employees </div></td>
    <td class="style2"><div align="left">
    <input type="checkbox" name="checkbox2" value="checkbox">
    </div></td>
    <td class="style2">&nbsp;</td>
    <td class="style2">&nbsp;</td>
    <td class="style2">&nbsp;</td>
    <td class="style2">&nbsp;</td>
    </tr>
    </table><br>
    <img src="images/red.jpg" width="10" height="10">&nbsp;=&nbsp;<em>not eligable
    </em><br>
    <input name="" type="submit" value="Submit">
    </form>

    StokeyTCI Guest

  7. #7

    Default Re: dynamically name text field

    Yep, just as I suspected.

    Here's your FORM code: <form action="inputtosql.cfm" method="get">

    Change the method to method="post"
    J.C. Guest

  8. #8

    Default Re: dynamically name text field

    after looking at the link, if you can come up with a better way to achieve what
    im trying to do, after focus out on the fields im going to do a post back, and
    subtract what ever was put in from the available balance. On submit im going to
    have to email regional director, and input into sql database for approval

    StokeyTCI Guest

  9. #9

    Default Re: dynamically name text field

    Is the page posting to itself? If so, then you need to set a param inside the output loop:

    <cfoutput query="getemp">
    <cfparam name="FORM.#EMPNUM#INCREASE" default="">
    </cfoutput>


    J.C. Guest

  10. #10

    Default Re: dynamically name text field

    I changed it on the main site

    check the link again and you will see the error.
    StokeyTCI Guest

  11. #11

    Default Re: dynamically name text field

    I haven't coded the post back yet, but here is what it will do in javascript

    function postback(){
    doent.form.action = "main.cfm";
    doent.form.submit();
    }

    just lets me reload the page on events

    StokeyTCI Guest

  12. #12

    Default Re: dynamically name text field

    Yep, there's an error.

    Post the code for the ENTIRE page so I can understand what's going on. It looks like the page you have in your link is main.cfm and it posts to inputsql.cfm.


    J.C. Guest

  13. #13

    Default Re: dynamically name text field

    Normally, I wouldn't dynamically name the input field, I would check to see if
    it exists like so

    <cfif isdefined("form.textfield")>
    <cfif #form.textfield# is not "">
    do the math
    </cfif>
    <cfelse>
    <cfoutput query="getbudg">
    #budget#
    </cfif>

    StokeyTCI Guest

  14. #14

    Default Re: dynamically name text field

    <cfset form.storenum = 357>
    <cfquery name="getemp" datasource="paycalc">
    Select empnum, Name, rehiredate, Salary, Storenum, post, year(rehiredate) as
    hireyear
    From employees
    where storenum = #form.storenum#
    </cfquery>

    <cfquery name="getbudg" datasource="paycalc">
    Select Budget
    from storebudg
    where storecode = '#form.storenum#'
    </cfquery>


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Payroll Overview</title>
    <meta http-equiv="Content-Type" content="text/html; cht=iso-8859-1">
    <style type="text/css">
    <!--
    body {
    margin-left: 0px;
    margin-top: 0px;
    margin-right: 0px;
    margin-bottom: 0px;
    }
    table#header {
    border-bottom:thin solid #666666;
    }
    table#body {
    border-left:thin solid #666666;
    border-right:thin solid #666666;
    border-bottom:thin solid #666666;
    }
    td#menu {
    border-right:thin solid #666666;

    font-family: Arial, Helvetica, sans-serif;
    font-size:x-small;
    font-weight: bold;
    }
    div#tabledata{
    border-left:thin solid #666666;
    }
    table#data{
    border-right:thin solid #666666;
    border-bottom:thin solid #666666;

    }
    table#headerdata{
    border-right:thin solid #666666;
    border-bottom:thin solid #666666;
    font-family: Arial, Helvetica, sans-serif;
    font-size: x-small;
    }
    table#menudata{

    border-bottom:thin solid #666666;
    font-family: Arial, Helvetica, sans-serif;
    font-size: x-small;
    font-weight: bold;

    }
    .style2 {
    font-size: x-small;
    font-weight: bold;
    }
    .style4 {font-size: small}
    a:link {
    color: #000000;
    text-decoration: none;
    }
    a:visited {
    color: #000000;
    text-decoration: none;
    }
    a:hover {
    color: #ab273e;
    text-decoration: none;
    }
    a:active {
    text-decoration: none;
    }
    .style7 {font-size: x-small; font-family: Arial, Helvetica, sans-serif; }
    .style8 {
    font-size: x-small;
    font-family: Arial, Helvetica, sans-serif;
    color: #AB273E;
    }
    .style9 {font-size: x-small; font-weight: bold; color: #FFFFFF; }
    .style10 {
    color: #FFFFFF;
    font-weight: bold;
    font-style: italic;
    }
    -->
    </style></head>

    <body>
    <table width="100%" height="50" border="0" cellpadding="0" cellspacing="0"
    id="header">
    <tr >
    <td width="33%" height="50" background="images/spacer.gif"
    bgcolor="#FFFFFF"><img src="images/logo.jpg" width="45" height="45"><span
    class="style10">Raise Calculator </span></td>
    <td width="34%" height="50"><img src="images/gradient.jpg" width="300"
    height="50"></td>
    <td width="33%"><div align="right"></div></td>
    </tr>
    <tr>
    <td height="10" colspan="3" bgcolor="#666666"></td>
    </tr>
    </table>

    <table width="100%" border="0" cellpadding="0" cellspacing="0" id="body">
    <tr>
    <td width="15%" valign="top" id="menu"> <table width="100%" border="1"
    cellpadding="2" cellspacing="0" id="menudata" >
    <tr>
    <td bgcolor="#AB273E"><div align="center"
    class="style9">Menu</div></td>
    </tr>
    <tr>
    <td><img src="images/redcircle.gif" width="10"
    height="10">&nbsp;&nbsp;Main</td>
    </tr>
    <tr>
    <td>Who's Eligable </td>
    </tr>
    <tr>
    <td>Raise Reasons </td>
    </tr>
    </table></td>
    <td colspan="2" valign="top" >
    <form action="inputtosql.cfm" method="post">
    <table width="100%" border="0" cellpadding="0" cellspacing="0">
    <tr class="style2">
    <td width="33%">Available Budget </td>
    <td width="33%">&nbsp;</td>
    <td>
    <div align="right">Center Id </div></td>
    </tr>
    <tr class="style2">
    <td width="33%">
    <cfoutput query="getemp">
    <cfif NOT EVALUATE('FORM.#EMPNUM#INCREASE') IS "">
    <input name="text" type="text" disabled size="10" value="defined">
    <cfelse>
    <input name="text" type="text" disabled size="10"
    value="#dollarformat(getbudg.budget)#">
    </cfif>
    </cfoutput>
    </td>

    <td width="33%">&nbsp;</td>
    <td>
    <div align="right">
    <input type="text" value="<cfoutput>#form.storenum#</cfoutput>"
    size="5" disabled>
    </div></td>
    </tr>
    </table>

    <br>
    <br>

    <table width="100%" border="1" cellpadding="2" cellspacing="0"
    bordercolor="#000000">
    <tr class="style2">
    <td width="12%">Employee # </td>
    <td width="18%">Name</td>
    <td width="13%">Position</td>
    <td width="16%">Hire Date </td>
    <td width="12%">Salary</td>
    <td width="14%">Increase</td>
    <td width="15%">% of Change </td>

    </tr>
    <cfoutput query="getemp">
    <cfif #hireyear# lt #dateformat(now(),"yyyy")#>
    <tr>
    <td><span class="style7">#empnum#</span></td>
    <td><span class="style7">#name#</span></td>
    <td><span class="style7">#post#</span></td>
    <td><span
    class="style7">#dateformat(rehiredate,"mm/dd/yyyy")#</span></td>
    <td><span class="style7">#dollarformat(salary)#</span></td>
    <td><div align="center">
    <input name="#empnum#increase" type="text" size="5">
    </div></td>
    <td>&nbsp;</td>
    </tr>
    <cfelse>
    <tr>
    <td><span class="style8">#empnum#</span></td>
    <td><span class="style8">#name#</span></td>
    <td><span class="style8">#post#</span></td>
    <td><span
    class="style8">#dateformat(rehiredate,"mm/dd/yyyy")#</span></td>
    <td><span class="style8">#dollarformat(salary)#</span></td>
    <td><div align="center">
    <input name="#empnum#increase" type="text" size="5" disabled>
    </div></td>
    <td>&nbsp;</td>
    </tr>
    </cfif>
    </cfoutput>

    <tr>
    <td colspan="4"><div align="right" class="style2">Total</div></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>

    </tr>
    </table>
    <br>
    <br>
    <table width="100%" border="0" cellpadding="0" cellspacing="0">
    <tr>
    <td colspan="2" class="style2"><div align="right">Apply % across all
    employees </div></td>
    <td width="18%" class="style2">
    <div align="left">
    <input type="checkbox" name="checkbox" value="checkbox">
    </div></td><td width="20%" class="style2"><div
    align="right">Percentage&nbsp;&nbsp;&nbsp;</div></td>
    <td width="23%" class="style2"><input name="textfield" type="text"
    size="3">
    %</td>
    <td width="3%" class="style2">&nbsp;</td>
    <td width="5%" class="style2">&nbsp;</td>
    </tr>
    <tr>
    <td width="14%">&nbsp;</td>
    <td width="17%">&nbsp;</td>
    <td width="18%">&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td colspan="2" class="style2"><div align="right">Divide Budget across all
    employees </div></td>
    <td class="style2"><div align="left">
    <input type="checkbox" name="checkbox2" value="checkbox">
    </div></td>
    <td class="style2">&nbsp;</td>
    <td class="style2">&nbsp;</td>
    <td class="style2">&nbsp;</td>
    <td class="style2">&nbsp;</td>
    </tr>
    </table><br>
    <img src="images/red.jpg" width="10" height="10">&nbsp;=&nbsp;<em>not eligable
    </em><br>
    <input name="" type="submit" value="Submit">
    </form>
    </td>
    </tr> <tr>
    <td id="menu">&nbsp;</td>
    <td>&nbsp;</td>
    <td>

    <div align="right"><span class="style4"> </span></div></td>
    </tr>
    <tr >
    <td height="10" colspan="3" bgcolor="#666666"></td>
    </tr>
    </table>
    </body>
    </html>


    StokeyTCI Guest

  15. #15

    Default Re: dynamically name text field

    im taking out the math piece so you can see the end result again
    StokeyTCI Guest

  16. #16

    Default Re: dynamically name text field

    O btw thanks for the help, and if my logic is jacked and there is an easier way to do what im trying to do just yell
    StokeyTCI Guest

  17. #17

    Default Re: dynamically name text field

    The reason it's throwing the error is that initially, there is no post to this
    page. So you'll need to set a param like my example above. Place the code
    right under your output like this:

    <cfoutput query="getemp">
    <cfparam name="FORM.#EMPNUM#INCREASE" default="">
    <cfif NOT EVALUATE('FORM.#EMPNUM#INCREASE') IS "">

    What's confusing is that it posts to inputtosql.cfm. Looking at the code you
    posted, is that on a page named inputtosql.cfm? If not, what does
    inputtosql.cfm look like?

    J.C. Guest

  18. #18

    Default Re: dynamically name text field

    I have never used cfparam, I always use a post back in javascript, and build my
    queries dynamically with isdefined statments, I can post you an example of
    that. But what it does is 1 checks the form for valid data, then it submits if
    it passes the script, I then give an onclick to the submit button to call the
    form check function. My postback function just basically reloads the page, and
    I then use isdefined statments to dynamically build my where statments. I have
    had good luck with this in the past, only this time i'm trying to dynamically
    name the input fields. The reason for this is in the sql insert statment which
    is on inputtosql, I haven't wrote it yet but it will look like this

    <cfquery name="insertinfo" datasource="paycalc">
    insert into increases (empid, increase05)
    values ('#form.empid#', '#form#empnum#increase#')
    </cfquery>

    Only I know that the #'s around my dynamic form field are gonna throw another
    error

    If I only had one employee, I wouldn't have a problem, but the scope for this
    project is 3000 employees, CEO devides up budget for raises to 5 VP, the 5 vp
    devide it up to the 15 regional directors, the regional directors devide it out
    to the 170 stores the stores log on to the system and get a list of there
    employees, in the example I showed you there is 3. The store managers input
    the raises, what ever they input has to subtract from the budget they see on
    the screen, once they are done they submit it, it then waits for aproval from
    the regional directors, and then the vp, and then the ceo, Jeez the steps and
    procedures, lol. Anyway the problem im having right now is the employee list
    is ofcourse the result of a query. If I statically name the input field in the
    example I gave you the insert would insert 10000,10000, 10000 well this would
    obviously be wrong, so what im trying to do is name the input field with the
    employee id infront of the name increase ie #empnum#increase. This is
    presenting me with 2 problems 1 I can't check to see if the field is defined
    because of the #'s inside the isdefined statment ie <cfif
    isdefined('form.#empnum#increase')> because #empnum# is not defined the next
    problem is I know that the insert is also going to error our, and how would I
    do the syntax for the math because #dollarformat(budget -
    form.#empnum#increase)# also throws a syntax error. surely there has to be
    another way to do what im trying to do.


    Chris

    StokeyTCI Guest

  19. #19

    Default Re: dynamically name text field

    You'll still need the cfparam tag with your postback jscript code. Try it!
    J.C. Guest

Similar Threads

  1. Forms: Text field - auto fill another field?
    By LDVDG@adobeforums.com in forum Adobe Acrobat Macintosh
    Replies: 3
    Last Post: May 18th, 05:35 PM
  2. Defined text field in form -> subject field in e-mail
    By olaka in forum Dreamweaver AppDev
    Replies: 0
    Last Post: March 14th, 02:20 PM
  3. Replies: 2
    Last Post: February 22nd, 04:59 PM
  4. dynamically resize text field
    By blkli0n webforumsuser@macromedia.com in forum Macromedia Director Lingo
    Replies: 1
    Last Post: December 5th, 02:09 PM
  5. Linking date field to text field entry
    By Trey in forum Microsoft Access
    Replies: 1
    Last Post: July 16th, 07:35 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •