Use one List for multiple web pages - list

I have a webpage with the following code:
<td width="178>NAME:</td>
<td><select NAME="NAME" size="1" tabindex="1">
<option selected = true VALUE"">Please Specify</option>
<option VALUE=" Brown Dog">Brown Dog</option>
<option VALUE=" Blue Dog">Blue Dog</option>
<option VALUE=" Big Dog">Big Dog</option>
<option VALUE=" Bad Dog">Bad Dog</option>
...
</select>
</td>
</tr>
</tr>
This same exact code also resides in a number of other pages. When i update one page I have to update all of the other pages as well.
How can i code this information so it shows up in all of my webpages but only have to update it in one place?
Can I store this information in a file and call it in when the webpage is loaded?

Related

Coldfusion Server Side Validation Sometimes Required sometimes not depending on radio buttons

I am trying to get a better understanding of server side validation. I have been writing a lot of client side validation using JavaScript but did not realize if the user just turns JavaScript off the whole app does not validate any field. This is what I am looking into doing for ColdFusion Server side validation.
What I am wondering is how would you toggle on and off making a field required or not based on lets say a radio buttons yes or no. Say you have a radio button the if yes is chosen it makes another input required but if no is chosen it makes another field required. I was just wondering how you would do something like that with the _cf format of toggling on and off. Would you just create if statements on hidden fields to do so or something?
I have been researching it a lot and just was looking for some input on how people are achieving things like this because it just seems like you can do so much through client side but then its all pointless because they can just turn it off.
<table>
<tr>
<td>Date:</td>
<td><input type="text" name="date" size="20"></td>
<strong class="delete me and add my line number to the highlight in my pre tag">
<input type="hidden" name="date_cfformrequired" value="You must enter a date.">
<input type="hidden" name="date_cfformdate" value="The date you entered is not a valid date."></strong>
</tr>
<tr>
<td>Distance:</td>
<td><input type="text" name="distance" size="20"></td>
<strong class="delete me and add my line number to the highlight in my pre tag">
<input type="hidden" name="distance_cfformrequired" value="You must enter a distance.">
<input type="hidden" name="distance_cfformfloat" value="The distance you entered is not a valid number."></strong>
</tr>
<tr>
<td>Time:</td>
<td><input type="text" name="time" size="20"></td>
<strong class="delete me and add my line number to the highlight in my pre tag">
<input type="hidden" name="time_cfformrequired" value="You must enter a time.">
<input type="hidden" name="time_cfformregex" value="^\d{1,3}:\d{0,2}$"></strong>
</tr>
<tr>
<td>Comments:</td>
<td><input type="text" name="comments" size="50"></td>
<strong class="delete me and add my line number to the highlight in my pre tag">
<input type="hidden" name="comments_cfformrequired" value="You must enter a comment.">
<input type="hidden" name="comments_cfformmaxlength" value="50"></strong>
</tr>
<tr>
<td colspan="2" align="right">
<input type="submit" name="Add Entry">
</td>
</tr>
</table>
Your understanding of the difference between client and server side validation is correct. Consider that client side validation can be chalked up to a feature. Rather than the user entering information, submitting the form, and then being told something was incorrect, Javascript validation can guide them, but because it can be disabled, it's not good to rely on.
Server side validation always happens as dictated.
The code is pretty easy
As an example - HTML
Name:
<input type="text" name="myname">
Were you referred by a current user?
<input type="radio" name="Referred" value="0" checked> No
<input type="radio" name="Referred" value="1"> Yes
Who referred you?
<input type="text" name="ref_user">
Form processing
<cfset Err = {Messages = []}> // creates a struct named Err with an array names Messages.
<cfif len(trim(form.myname)) eq 0>
<cfset ArrayAppend(Err.Messages,"Please enter your name!">
</cfif>
<cfif form.Referred eq 1 and len(trim(form.ref_user)) eq 0>
<cfset ArrayAppend(Err.Messages,"You said someone referred you, who was it?">
</cfif>
<cfif ArrayLen(err.messages) eq 0>
...no errors, we can do form processing...
</cfif>
And then, when outputting your errors, if they exist
<cfif ArrayLen(err.messages) gt 0>
Sorry, an error occurred.<br>
<cfoutput>
<cfloop array="#err.messages#" index="cError">
- #cError#.<br>
</cfloop>
</cfoutput>
</cfif>
On the first line of the last code snippet, you'll see gt 0 at the end of the line. This is not necessary and most people will leave it off. You seem familiar with javascript, cf works the same way in that in that you might say
if (Err.Messages.length) {
... show
}
In cf, you can do similar, <cfif ArrayLen(Err.Messages)>.
Remember to either cfparam your variables or check for their existence in your form processing, like this..
<cfif not StructKeyExists(form, "Referred") or (form.Referred eq 1 and len(trim(form.ref_user)) eq 0)>
<cfset ArrayAppend(Err.Messages,"You said someone referred you, who was it?">
</cfif>

Error executing query, using ajax?

I'm updating a query using a form and ajax.
I added a new column (select option) to the form, it work before adding the select option.
I'm trying to get the value of the #dept_id# but i keep getting error
'NetworkError: 500 Error Executing Database Query'.
This has to do with the update query I have in delete_record.cfc.
when adding dept=#selectDept# to the query is when i get the error.
Taking this part off the query works and it updates.
Below its the form and after that its the delete_record.cfc file.
I also made a http://jsfiddle.net/6focvy54/4/
where I poster the ajax call and have the delete_record.cfc file code.
<form method="post" action="" id="confrm_key">
<table >
<tr>
<th >Add?</th>
<th >Delete?</th>
</tr>
<cfoutput query="total">
<tr id="hd#emp_id#">
<td>
<select name="selectDept" >
<option selected="selected" >Select Department</option>
<cfloop query="department">
<option value="#dept_id#">#dept_name#</option>
</cfloop>
</select>
</td>
<td> <input type="checkbox" name="check_delete" value="#emp_id#" >Yes</td>
</tr>
</cfoutput>
</table>
<p><input type="button" name="Submit" value="Remove" onclick="sub_keys();"></p>
</form>

Transfer Value from drop down to a

I need some help ...
I need the location drop down box to determine the appropriate inbox the form should be sent to.
ex if I choose Houston from the drop down box it will send it to the PayrollUSA email.
Im currently using a radio button to make the selection but i would like to automate with the drop down.
Im pretty new to this but im sure theres a if statement that can tie them together...
im using .asp for this.
<input type="radio" name="payroll" value="PayrollUSA#mail.com" checked="checked">US Payroll
<input type="radio" name="payroll" value="PayrollCAN#mail.com">CAN Payroll
<input type="radio" name="payroll" value="PayrollUK#mail.com">UK Payroll
<input type="radio" name="payroll" value="PayrollHK#mail.com">HK Payroll
Drop down selection
<SELECT SIZE="1" NAME="Business_Unit" style="width: 205px;" class="answers">
<option selected >Select</option>
<OPTION>Calgary</OPTION>
<OPTION>Chicago</OPTION>
<OPTION>Hong Kong</OPTION>
<OPTION>Houston</OPTION>
<OPTION>London</OPTION>
<OPTION>Los Angeles</OPTION>
<OPTION>Montreal</OPTION>
<OPTION>New York</OPTION>
<OPTION>New York Corporate</OPTION>
<OPTION>Philadelphia</OPTION>
<OPTION>San Francisco</OPTION>
<OPTION>Toronto</OPTION>
<OPTION>Toronto Corporate</OPTION>
<OPTION>Vancouver</OPTION>
</SELECT>
If you need the option value to be held then try this:
<SELECT SIZE="1" NAME="Business_Unit" style="width: 205px;" class="answers">
<option value="">Select an Option</option>
<option <% if Business_Unit= "PayrollCAN#mail.com" then %> selected <% End if %> value="PayrollCAN#mail.com">Calgary</option>
<option <% if Business_Unit= "PayrollUSA#mail.com" then %> selected <% End if %> value="PayrollUSA#mail.com">Chicago</option>
</select>
etc. for each option and same value may be used for different option displays
I imaging this should just be html based. So your option menu should look like:
<SELECT SIZE="1" NAME="Business_Unit" style="width: 205px;" class="answers">
<option value="-1">Select an Option</option>
<OPTION value="PayrollCAN#mail.com">Calgary</OPTION>
<OPTION value="PayrollUSA#mail.com">Chicago</OPTION>
<OPTION value="PayrollHK#mail.com">Hong Kong</OPTION>
<OPTION value="PayrollUSA#mail.com">Houston</OPTION>
<OPTION value="PayrollUK#mail.com">London</OPTION>
<OPTION value="PayrollUSA#mail.com">Los Angeles</OPTION>
<OPTION value="PayrollCAN#mail.com">Montreal</OPTION>
<OPTION value="PayrollUSA#mail.com">New York</OPTION>
<OPTION value="PayrollUSA#mail.com">New York Corporate</OPTION>
<OPTION value="PayrollUSA#mail.com">Philadelphia</OPTION>
<OPTION value="PayrollUSA#mail.com">San Francisco</OPTION>
<OPTION value="PayrollCAN#mail.com">Toronto</OPTION>
<OPTION value="PayrollCAN#mail.com">Toronto Corporate</OPTION>
<OPTION value="PayrollCAN#mail.com">Vancouver</OPTION>
</SELECT>
You can use the same value multiple times if needed

How to make date and time form values insert into one column?

I have a form where the user selects a date and time. The user's selections represent the time and date they want specific answers, which they enter in the same form, to display. Then I grab the selected values and insert them into a table: cse_result_summary. Right now my code is inserting them correctly.
I'm using this jquery plugin for the date. Time is just a simple select. Something I did not think about before I finish the form was how I would compare today's date to the show_date.
The code below will work for the show_date, but the problem is with the time. Even if the date is greater, but the time is not, it will have to wait for that time to display. I would like it to display at that specific time and date. When its after that date and time it should no longer matter the time it is.
Since I'm inserting the date and time in different columns, I'm wondering if its possible to insert them into one column? That way I will only have to compare todayDate > formDate:
<cfset dtToday = Now() />
<cfif DateFormat(dtToday, "yyyy--mm--dd") gte DateFormat(getdates.show_date)
&& TimeFormat(dtToday) gte timeformat(getdates.show_time)>
different file (form file)
<tr>
<td> Date it will display (Please enter date format mm/dd/yyyy.):</td>
<td><input class="inputDate" id="inputDate"
value="07/01/2014" NAME="date_used"/>
</td>
</tr>
<tr>
<td> Time it will display (Please enter time format hh:mm tt):
<td><select ID="time_used" NAME="time_used" VALIDATE="date" >
<option selected> Select Time</option>
<option value="7:00 AM">7:00 AM</option>
<option value="7:15 AM">7:15 AM</option>
<option value="7:30 AM">7:30 AM</option>
<option value="7:45 AM">7:45 AM</option>
<option value="8:00 AM">8:00 AM</option>
</select></TD>
</td>
</tr>
</tbody>
</table>
<p><input type="submit" name="Submit" value="Submit"></p>
</form>
<cfif FormSubmit eq "FormSubmitted">
... more code....
<cfset month_date_show = #DateFormat(Trim(form.month_date_show), "mm-15-yyyy")#>
<cfset newdate = #DateFormat(Trim(date_used), "mm-dd-yyyy")# />
<cfset time_used = #TimeFormat(Trim(time_used),"h:mm tt")#>
<cfquery datasource="Intranet" name="InsertRequest">
INSERT INTO cse_result_summary
( show_date, show_time,monthly_enter_date,monthly_past_date )
VALUES
( '#newdate#','#time_used#',getdate(),'#month_date_show#' )
</cfquery>
Assuming your database field type is date/time you could do something like this:
<tr>
<td> Date it will display (Please enter date format mm/dd/yyyy.):</td>
<td><input class="inputDate" id="inputDate" value="07/01/2014" NAME="date_used"/>
</td>
</tr>
<tr>
<td> Time it will display (Please enter time format hh:mm tt):
<td><select ID="time_used" NAME="time_used" VALIDATE="date" >
<option selected> Select Time</option>
<option value="7:00 AM">7:00 AM</option>
<option value="7:15 AM">7:15 AM</option>
<option value="7:30 AM">7:30 AM</option>
<option value="7:45 AM">7:45 AM</option>
<option value="8:00 AM">8:00 AM</option>
</select></TD>
</td>
</tr>
</tbody>
</table>
<p><input type="submit" name="Submit" value="Submit"></p>
</form>
<cfif FormSubmit eq "FormSubmitted">
... more code....
<cfset month_date_show = #DateFormat(Trim(form.month_date_show), "mm-15-yyyy")#>
<cfset newdate = #DateFormat(Trim(date_used), "mm-dd-yyyy")# />
<cfset time_used = #TimeFormat(Trim(time_used),"h:mm tt")#>
<Cfset combinedDateTime="#newdate #time_used#">
<cfquery datasource="Intranet" name="InsertRequest">
INSERT INTO cse_result_summary (show_date, show_time,monthly_enter_date,monthly_past_date, *yourcolumname*)
VALUES ('#newdate#','#time_used#',getdate(),'#month_date_show#', <cfqueryparam cfsqltype="cf_sql_timestamp" value="#combinedDateTime#">)
</cfquery>

ColdFusion 9 ReReplace nth occurence of HTML tag

I have the following HTML stored in a variable in ColdFusion 9. I need to insert a new table row after the 4th </tr>. i.e. before the Submit button.
<form name="form1" id="form1" action="" method="post">
<table>
<tr style="visibility:hidden;display:none;"><td> <input type="hidden" id="ref1" name="ref1" value="1" > </td></tr>
<tr style="visibility:hidden;display:none;"><td> <input type="hidden" id="ref2" name="ref2" value="2" > </td></tr>
<tr>
<th style="text-align:left;">Name * </th>
<td><input type="text" name="foo" id="foo" size="30" maxlength="50" value=""></td>
</tr>
<tr>
<th title="Please enter plain text or HTML." style="cursor:help;text-align:left;">Comment * </th>
<td><textarea name="bar" id="bar" cols="40" rows="10" ></textarea></td>
</tr>
<tr>
<th colspan="1"></th>
<td>
<input style="width:80px" type="submit" value="Submit">
<input style="width:80px" type="button" value="Cancel">
</td>
</tr>
</table>
ReReplace seems like the way to go, but I'm having trouble getting the regexp right. Another option would be to split the string and rebuild it with my new HTML in the middle. Any suggestions would be appreciated.
Regex is the wrong tool for this - you want a HTML parser.
Here's how you can do it with JSoup:
<cfsavecontent variable="InputHtml">
[insert code from question]
</cfsavecontent>
<cfsavecontent variable="NewRow">
<tr><th>whatever</th><td>stuff</td></tr>
</cfsavecontent>
<!--- Read "Creating Objects From Jar Files" --->
<cfset jsoup = createObject('java','org.jsoup.Jsoup') />
<cfset HtmlDom = jsoup.parse(InputHtml) />
<cfset HtmlDom.select('tr:eq(4)').after( NewRow ) />
<cfoutput>
<pre>#XmlFormat(HtmlDom.body().html())#</pre>
</cfoutput>
You can see details of what selectors are supported in the JSoup Selector API
If you don't know/care how many lines are in the table, you can do...
HtmlDom.select('table>tbody').append( NewRow )
...to just add the new row at the end.
Creating Objects From Jar Files
The above code most likely wont work instantly if you copy and paste it, because your server doesn't know about JSoup - you need to download the Jar file and put it in a sensible location.
For CF9, you need to copy the jsoup-1.6.3.jar into your {coldfusion}/lib directory then restart the server.
For CF10, you can use this.JavaSettings in your Application.cfc (as described here) to place it in a different location.
For Railo and OpenBD, you can specify the location of the JAR file as a third argument, e.g:
<cfset jsoup = createObject('java','org.jsoup.Jsoup','lib/jsoup-1.6.3.jar') />
I recommend doing this with jQuery:
​$(document).ready(function(){
$($('form tr')[3]).after('<tr><td>row</tr></tr>');
});​
Much easier.