Saturday, April 16, 2005

Coldfusion Date Compare

Question: I am trying to compare dates in a query between today, and every date in my db.

<cfquery datasource="Parks" name="AllEventDates">
SELECT * from Events
</cfquery>

<cfoutput query="AllEventDates">
<cfset comparison = DateCompare(#DateFormat(Now())#,,#DateFormat(AllEventDates.Expires, "mmm/dd/yyyy")#)>
</cfoutput>

Apparently that is wrong, and I don't know how to compare dates in SQL.

Answer: Well, for starters to get you going, here's the reference page for DateFormat: http://livedocs.macromedia.com/coldfusion/6.1/htmldocs/functi56.htm#wp4762855

Friday, April 15, 2005

Change Background with Javascript

How do I change the background of a <td> using javascript.

<script language="javascript">
function shade(idx) {
str = "sp_" + idx;
//How to shade the <td> tag with the id of str?
}
</script>

<table>
<tr>
<td id="sp_1"></td>
<td id="sp_2"></td>
<td id="sp_3"></td>
<td id="sp_4"></td>
<td id="sp_5"></td>
<td id="sp_6"></td>
</tr>
<tr>
<td colspan="6"><input type="button" onClick="shade(6)"></td>
</tr>
</table>

How do I change the background color of sp_6 since I know the id name only but now the object? How do I get the object name "sp_6"?

Any help would be very much appreciated. Thanks

Answer:
<script language="javascript">
function shade(idx) {
str = "sp_" + idx;
document.getElementById(str).style.background="xxxx";
}
</script>

Thursday, April 14, 2005

Javascript Button Disabled

Question: I have a form whose fields are populated by a dropdown called "layoutlist". There is also a button called "reportsubmit". Now if you choose a report and click the "reportsubmit" button BEFORE the page has loaded, you get an output of the PREVIOUS report you chose. So what I want to do is disable the button as soon as you make a choice in "layoutlist." Then I want to enable it once the page has completely loaded.

I've tried an inline script right after the form field:
<script>
document.rptform.reportsubmit.disabled = true;
</script>

Then at the end of the page:
<cfif isDefined("form.layoutlist") and form.layoutlist IS NOT "NONE">
<script>
for (i=1; i<=1000000; i=i+1)
{
}
document.rptform.reportsubmit.disabled = false;
</script>
</cfif>

Which works great the first time you come to the page. However, once you are there and the button is enabled, choosing another layout doesn't disable the "reportsubmit" button right away.

Answer:
<select name="layoutlist" OnChange="formSubmit('null');"
onFocus="rptform.reportsubmit.disabled=true;">
--the "onFocus" part is what I added

<input type="button" name="reportsubmit" value="Excel Output"
onClick="formSubmit('reportsubmit');" />
--this is the button to disable

Immediately disables the reportsubmit button when I click on "layoutlist". But why does the reportsubmit button re-enable itself once the page is loaded? I am so glad that it does! Can anyone explain to me why?

Wednesday, April 13, 2005

Disable The Enter Key

I am trying to disable the enter key in a form - it works in IE but can I get it to work in Netscape or other browsers?

This block of Javascript should do the trick.

function BlockCR()
{
if (event.keyCode == 13) return false;
return true;
}

input type="Text" name="Foo" onkeydown="return BlockCR()"

Tuesday, April 12, 2005

Coldfusion and CGI Variables

Anyone know where I can get a list of all CGI.- variables?

<cfdump var=#cgi#>

Below is code I use if I need to know a CGI value is for a given browser/etc. It also saves the data to a text file on the server so that if you're browsing via a cell phone/PDA, you can still easily pull up the information in your browser.

<cfset c=Chr(10)>

<cfset Out=
"CF: #Server.ColdFusion.ProductVersion#" & c &
"OS: [#Server.OS.Name#]" & c &
"OS Ver: [#Server.OS.Version#]" & c>

<cfset KeyList=StructKeyList(CGI)>
<cfloop index="Key" list="#KeyList#">
<cfset CVal=Evaluate("CGI.#Key#")>
<cfset Out=Out & "#Key#: [#CVal#]" & c>
</cfloop>

<cfoutput><pre>#Out#</pre></cfoutput>

<cffile action="WRITE" file="#GetDirectoryFromPath(GetCurrentTemplatePath())#cgi.txt" output="#Out#" addnewline="No">

Monday, April 11, 2005

New episode of the show

A new episode of the John and Steve Show has been released, The John and Steve Show - Brother-in-Laws Gone Wild! These guys are flashing their wits all over the place.

Go to the site now and download it.

Sunday, April 10, 2005

Dynamic Image Border

Is there a way to make all images with links not have a border? Is this possible using css or do I have to use html on every tag?

You can do it either way, CSS is much easier because you just have to add class=classname and then define the element classname in your style sheet, doing it this way you can build the class into a dynamic statement.

.pictureborder {
border: dotted #FFFF66;
}

And in the page you can add the class like this:

img src="picture.jpg" class="pictureborder"