Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.
-
StokeyTCI #1
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
-
Forms: Text field - auto fill another field?
Someone PLEASE help me... how do i structure a form so that when text is entered into one field, it auto-fills other fields on the form that are... -
Defined text field in form -> subject field in e-mail
Hi, I have a form on my web site which users send to me by mailto-function. I would like the text they write in a particular text field to... -
Radio btn makes text field equal value of different text field
What I am trying to do is when someone clicks on the YES radio button I want the text field called MYTEXT to equal the text field named DATE. The... -
dynamically resize text field
Hi, I need to be able to adjust my text fields during runtime an then export the height and width of my field to a text file. example... -
Linking date field to text field entry
Is there a way to setup a date field that will automatically enter the date when any information is entered into a field next to it? -
J.C. #2
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
-
StokeyTCI #3
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
-
J.C. #4
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
-
StokeyTCI #5
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
-
StokeyTCI #6
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%"> </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%"> </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> </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> </td>
</tr>
</cfif>
</cfoutput>
<tr>
<td colspan="4"><div align="right" class="style2">Total</div></td>
<td> </td>
<td> </td>
<td> </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 </div></td>
<td width="23%" class="style2"><input name="textfield" type="text"
size="3">
%</td>
<td width="3%" class="style2"> </td>
<td width="5%" class="style2"> </td>
</tr>
<tr>
<td width="14%"> </td>
<td width="17%"> </td>
<td width="18%"> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </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"> </td>
<td class="style2"> </td>
<td class="style2"> </td>
<td class="style2"> </td>
</tr>
</table><br>
<img src="images/red.jpg" width="10" height="10"> = <em>not eligable
</em><br>
<input name="" type="submit" value="Submit">
</form>
StokeyTCI Guest
-
J.C. #7
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
-
StokeyTCI #8
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
-
J.C. #9
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
-
StokeyTCI #10
Re: dynamically name text field
I changed it on the main site
check the link again and you will see the error.
StokeyTCI Guest
-
StokeyTCI #11
Re: dynamically name text field
I haven't coded the post back yet, but here is what it will do in javascript
function postback(){
document.form.action = "main.cfm";
document.form.submit();
}
just lets me reload the page on events
StokeyTCI Guest
-
J.C. #12
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
-
StokeyTCI #13
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
-
StokeyTCI #14
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; charset=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"> 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%"> </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%"> </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> </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> </td>
</tr>
</cfif>
</cfoutput>
<tr>
<td colspan="4"><div align="right" class="style2">Total</div></td>
<td> </td>
<td> </td>
<td> </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 </div></td>
<td width="23%" class="style2"><input name="textfield" type="text"
size="3">
%</td>
<td width="3%" class="style2"> </td>
<td width="5%" class="style2"> </td>
</tr>
<tr>
<td width="14%"> </td>
<td width="17%"> </td>
<td width="18%"> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </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"> </td>
<td class="style2"> </td>
<td class="style2"> </td>
<td class="style2"> </td>
</tr>
</table><br>
<img src="images/red.jpg" width="10" height="10"> = <em>not eligable
</em><br>
<input name="" type="submit" value="Submit">
</form>
</td>
</tr> <tr>
<td id="menu"> </td>
<td> </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
-
StokeyTCI #15
Re: dynamically name text field
im taking out the math piece so you can see the end result again
StokeyTCI Guest
-
StokeyTCI #16
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
-
J.C. #17
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
-
StokeyTCI #18
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
-
J.C. #19
Re: dynamically name text field
You'll still need the cfparam tag with your postback jscript code. Try it!
J.C. Guest



Reply With Quote

