lantervj
asked on
need help with simple problem - javascript
I'm having trouble formatting the message I want to present. All work fine until I add lastname to the message. I get an error that says "Jones is undefined" if Jones happened to be the lastname.
function cnfDelete (userid, lastname)
{
var deletemessage = 'Are you sure you want to delete this record? '.concat(userid,' ', lastname);
if ( confirm(deletemessage))
{
return true;
}
else
{
return false;
}
}
function cnfDelete (userid, lastname)
{
var deletemessage = 'Are you sure you want to delete this record? '.concat(userid,' ', lastname);
if ( confirm(deletemessage))
{
return true;
}
else
{
return false;
}
}
ASKER
That's how I initially wrote it. I get "King is not defined. Here is the code that fires the function;
<input type="image" value="#CallList.usersID#" src="#request.controlURL#i mages/dele te.gif" name="test" onClick="javascript: this.form.deleteCLUser.val ue='#callL ist.usersi d#'; return cnfDelete(#CallList.UsersI D#,#CallLi st.lastnam e#);"></td >
function cnfDelete (userid, lastname)
{
var deletemessage = 'Are you sure you want to delete this record? '+(userid+' '+lastname);
if ( confirm(deletemessage))
{
return true;
}
else
{
return false;
}
}
<input type="image" value="#CallList.usersID#"
function cnfDelete (userid, lastname)
{
var deletemessage = 'Are you sure you want to delete this record? '+(userid+' '+lastname);
if ( confirm(deletemessage))
{
return true;
}
else
{
return false;
}
}
change from
]<input type="image" value="#CallList.usersID#" src="#request.controlURL#i mages/dele te.gif" name="test" onClick="javascript: this.form.deleteCLUser.val ue='#callL ist.usersi d#'; return cnfDelete(#CallList.UsersI D#,#CallLi st.lastnam e#);"></td >
to
<input type="image" value="#CallList.usersID#" src="#request.controlURL#i mages/dele te.gif" name="test" onClick="javascript: this.form.deleteCLUser.val ue='#callL ist.usersi d#'; return cnfDelete('#CallList.Users ID#','#Cal lList.last name#');"> </td>
]<input type="image" value="#CallList.usersID#"
to
<input type="image" value="#CallList.usersID#"
ASKER
I just happened to get a name of O'Brien and the apostrophe got in the way. I delimited using quotes but that still didn't work. I could use a regular expression to strip out the apostrophes. Can you think of a better way?
did you tried this ?
<input type="image" value="#CallList.usersID#" src="#request.controlURL#i mages/dele te.gif" name="test" onClick='javascript: this.form.deleteCLUser.val ue="#callL ist.usersi d#"; return cnfDelete("#CallList.Users ID#","#Cal lList.last name#");'> </td>
or this?
<input type="image" value="#CallList.usersID#" src="#request.controlURL#i mages/dele te.gif" name="test" onClick="javascript: this.form.deleteCLUser.val ue=escape( '#callList .usersid#' ); return cnfDelete(escape('#CallLis t.UsersID# '),escape( '#CallList .lastname# '));"></td >
<input type="image" value="#CallList.usersID#"
or this?
<input type="image" value="#CallList.usersID#"
replace single quote with escape character
like..
from
O'Brien
to
O\'Brien
like..
from
O'Brien
to
O\'Brien
ASKER
I can't change whats' coming from the database.
ASKER
When I try a different records (without an apostrophe in the name) I get ;
Error: syntax error
Source File: https://dev.taxtalent.net/control/calllist/index.cfm?fa=view&CFGRIDKEY=1605#
Line: 1, Column: 67
Source Code:
javascript: this.form.deleteCLUser.val ue='90064' ; return cnfDelete(
Error: syntax error
Source File: https://dev.taxtalent.net/control/calllist/index.cfm?fa=view&CFGRIDKEY=1605#
Line: 1, Column: 67
Source Code:
javascript: this.form.deleteCLUser.val
ASKER
I tried delimiting just the lastname with the backward apostrophe and got;
Error: illegal character
Source File: https://dev.taxtalent.net/control/calllist/index.cfm?fa=view&CFGRIDKEY=1605#
Line: 1, Column: 73
Source Code:
javascript: this.form.deleteCLUser.val ue='89281' ; return cnfDelete(89281,`Polking`) ;
Error: illegal character
Source File: https://dev.taxtalent.net/control/calllist/index.cfm?fa=view&CFGRIDKEY=1605#
Line: 1, Column: 73
Source Code:
javascript: this.form.deleteCLUser.val
looks like you are using coldfusion..
then try this
<input type="image" value="#CallList.usersID#" src="#request.controlURL#i mages/dele te.gif" name="test" onClick="javascript: this.form.deleteCLUser.val ue=escape( '#callList .usersid#' ); return cnfDelete('#replace(CallLi st.UsersID ,"'","\'", "all")#',' #replace(C allList.la stname,"'" ,"\'","all ")#');"></ td>
then try this
<input type="image" value="#CallList.usersID#"
ASKER
I' getting "invalid CFML construct...".
<input type="image" value="#CallList.usersID#" src="#request.controlURL#i mages/dele te.gif" name="test" onClick="javascript: this.form.deleteCLUser.val ue='#callL ist.usersi d#'; return cnfDelete(#CallList.UsersI D#,#RErepl ace(CallLi st.lastnam e, '[^a-zA-Z0-9]', '\','all'));"></td>
<input type="image" value="#CallList.usersID#"
try with just replace function..
return cnfDelete('#CallList.Users ID#','#rep lace(CallL ist.lastna me, "'","\'","all")#');
return cnfDelete('#CallList.Users
ASKER
I did, in fact, have a missing # sign. Now I get;
Error: illegal character
Source File: https://dev.taxtalent.net/control/calllist/index.cfm?fa=view&CFGRIDKEY=1605#
Line: 1, Column: 74
Source Code:
javascript: this.form.deleteCLUser.val ue='27159' ; return cnfDelete(27159,O\\Brien);
.......................... .......... .......... .......... .......... .......... .......... .......... .......... .^
So, the user ID and lastname are passing.
Error: illegal character
Source File: https://dev.taxtalent.net/control/calllist/index.cfm?fa=view&CFGRIDKEY=1605#
Line: 1, Column: 74
Source Code:
javascript: this.form.deleteCLUser.val
..........................
So, the user ID and lastname are passing.
did you copied my code above ?? or please post the code...
I see that single quotes are missing for arguments....
I see that single quotes are missing for arguments....
ASKER
If the name (Tsapralis) does not have a special character in it, I don't get the confirm box but the record does delete. I get;
Error: Tsapralis is not defined
Source File: https://dev.taxtalent.net/control/calllist/index.cfm?fa=view&CFGRIDKEY=1605#
Line: 1
Error: Tsapralis is not defined
Source File: https://dev.taxtalent.net/control/calllist/index.cfm?fa=view&CFGRIDKEY=1605#
Line: 1
ASKER
<input type="image" value="#CallList.usersID#" src="#request.controlURL#i mages/dele te.gif" name="test" onClick="javascript: this.form.deleteCLUser.val ue='#callL ist.usersi d#'; return cnfDelete(#CallList.UsersI D#,#RErepl ace(CallLi st.lastnam e, '[^a-zA-Z0-9]', '\','all')#);"></td>
function cnfDelete (userid, lastname)
{
var deletemessage = 'Are you sure you want to delete this record? '+(userid+' '+lastname);
if ( confirm(deletemessage))
{
return true;
}
else
{
return false;
}
}
function cnfDelete (userid, lastname)
{
var deletemessage = 'Are you sure you want to delete this record? '+(userid+' '+lastname);
if ( confirm(deletemessage))
{
return true;
}
else
{
return false;
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That did it. Live and learn. Thanks.
ASKER
Great response. Patience.
ASKER
You wouldn't want to look at my cfajaxproxy question would you?
please post...
I will back in 20 to 30 mins..
I will back in 20 to 30 mins..
var deletemessage = 'Are you sure you want to delete this record? '+userid+' '+lastname;