EasyCFM.COM ColdFusion Forums / ASP to CFML / need converting this code..

   Reply to Discussion | New Discussion << previous || next >> 
Posted By Discussion Topic: need converting this code..

book mark this topic Printer-friendly Version  send this discussion to a friend  new posts last

specific
01-01-2008 @ 2:08 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 897
Joined: Apr 2006

i have this code, but i tried i think something is missing.. will both both asp and my generated coldfusion code..

please see if my cfm generated code is wrong or right, beacuse it is not working:

ASP code:

dim strCmd
dim strUsername

strCmd = trim(Request.Form("strCmd").Item)
strUsername = trim(Request.Form("strUsername").Item)

select case strCmd
case "availability"
strSQL = "SELECT USERNAME FROM FELONS WHERE USERNAME = '" & strUsername & "'"
objRS.Open strSQL,objSecureDb.conn,adOpenForwardOnly,adLockReadOnly,adCmdText
if objRS.EOF then
Response.Write("Username " + strUsername + " is available")
else
Response.Write("Username " + strUsername + " is unavailable")
end if
case else
Response.Write("Invalid command: " + strCmd)
end select




my CFM generated

<cfparam name="strCmd" default="">
<cfparam name="strUsername" default="">

<cfset str = trim(strCmd)>
<cfset strU = trim(form.newuserid)>

<cfswitch expression="str">
<cfcase value="avaliability">
<cfquery datasource="#request.dsn#" name="check">
SELECT uniquename FROM
registration
WHERE
uniquename = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#TRIM(strU)#">
</cfquery>
<cfif check.recordcount GT 0>
     <cfset msg = "Username Already Taken">
<cfelse>
     <cfset msg = "Username is avaliable">
</cfif>
</cfcase>
<cfdefaultcase>
Error
</cfdefaultcase>
</cfswitch>


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The Door to Coldfusion Community Will Remain Open Till World Ends

Want a Web Portal Contact Me

randhawaz81@gmail.com

<cf_visitwebsite>

http://portal.randhawaworld.com/

</cf_visitwebsite>

CJ
01-02-2008 @ 9:42 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Administrator
Posts: 4262
Joined: Oct 2002

think you could be a little more helpful than "it is not working"?

*how* is it not working?  are you getting an error?  if so, what error?

it's way easier to look at code and debug it if you know what the problem is.  if you're going to ask for help debugging code, please do us the courtesy of letting us know what we're trying to fix.

-CJ-
@ #coldfusion/DALNet
http://charlie.griefer.com

Teachers open the door. You enter by yourself.
—Chinese Proverb

specific
01-04-2008 @ 1:49 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 897
Joined: Apr 2006

well i am enabling a checkusername before submitting to the database using AJAX, i have the code for the ajax but getting into problem when i try to send the post to the checkavaliability.cfm page:

here is the ajax code i am using:

<!--- Start of Ajax Functionality ---!>

function OnChangedUsername()
{
if(document.form1.newuserid.value == "")
{
document.form1.btnCheckAvailability.disabled = true;
}
else
{
document.form1.btnCheckAvailability.disabled = false;
}
}

function OnCheckAvailability()
{
if(window.XMLHttpRequest)
{
oRequest = new XMLHttpRequest();
}
else if(window.ActiveXObject)
{
oRequest = new ActiveXObject("Microsoft.XMLHTTP");
}

oRequest.open("POST", "checkavaliability.cfm", true);
oRequest.onreadystatechange = UpdateCheckAvailability;

oRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
oRequest.send("strCmd=availability&strUsername=" + document.form1.newuserid.value);
}

function UpdateCheckAvailability()
{
if(oRequest.readyState == 4)
{
if(oRequest.status == 200)
{
document.getElementById("Available").innerHTML = oRequest.responseText;
}
else
{
document.getElementById("Available").innerHTML = "Asychronous Error";
}
}
}

on my main page i use it like this:

<tr>
              <td colspan="2">Choose  Name: </td>
            </tr>
            <tr>
              <td width="23%"><input name="newuserid" type="text" id="newuserid" size="35" onKeyUp="OnChangedUsername();" value="#Form.newuserid#" />
                *</td>
              <td width="77%"><input id="btnCheckAvailability" type="button" disabled="disabled"
            value="Check Availability" onClick="OnCheckAvailability();" /></td>
            </tr>
            <tr>
              <td colspan="2"><div ID="Available"></div></td>
            </tr>

but the method is not passing i do not why, the code of cfm file is above as you have seen, it just don't work,

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The Door to Coldfusion Community Will Remain Open Till World Ends

Want a Web Portal Contact Me

randhawaz81@gmail.com

<cf_visitwebsite>

http://portal.randhawaworld.com/

</cf_visitwebsite>

CJ
01-04-2008 @ 12:16 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Administrator
Posts: 4262
Joined: Oct 2002

boy i love hearing "it just don't work".

look in the docs for <cfswitch>.  you're missing a rather basic, but very important bit in the following line of code:

<cfswitch expression="str">

i'm not saying that this will fix it... but this is certainly one of the problems.

if you're going to be using AJAX type stuff, i highly recommend you use firefox with the firebug plugin.  the plugin will let you see the data coming back from the XMLHttp request call, so even if there's an error, and the browser can't render it, you can still see it.

the kind of information you'll be able to ascertain using firebug will be useful to you (if for no other reason than to post when asking for help in a forum... much better than "it just don't work".

-CJ-
@ #coldfusion/DALNet
http://charlie.griefer.com

Teachers open the door. You enter by yourself.
—Chinese Proverb

louissto56
01-07-2008 @ 2:25 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 1149
Joined: Jan 2007

@CJ I love hearing "it just worked" even more Wink

try

<cfswitch expression="#str#">

Thats if str is an actual variable.


____________________________
My Biz List.com.au :: Feb 08


Website Designed and Developed by Pablo Varando.