Link to home
Start Free TrialLog in
Avatar of lantervj
lantervjFlag for United States of America

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;
      }
      }
Avatar of Sudhindra A N
Sudhindra A N
Flag of India image

try with this..
var deletemessage = 'Are you sure you want to delete this record?  '+userid+' '+lastname;
Avatar of lantervj

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#images/delete.gif" name="test" onClick="javascript: this.form.deleteCLUser.value='#callList.usersid#'; return cnfDelete(#CallList.UsersID#,#CallList.lastname#);"></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;
      }
      }
change from
]<input type="image" value="#CallList.usersID#" src="#request.controlURL#images/delete.gif" name="test" onClick="javascript: this.form.deleteCLUser.value='#callList.usersid#'; return cnfDelete(#CallList.UsersID#,#CallList.lastname#);"></td>

to

<input type="image" value="#CallList.usersID#" src="#request.controlURL#images/delete.gif" name="test" onClick="javascript: this.form.deleteCLUser.value='#callList.usersid#'; return cnfDelete('#CallList.UsersID#','#CallList.lastname#');"></td>
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?
Avatar of Gurvinder Pal Singh
did you tried this ?

<input type="image" value="#CallList.usersID#" src="#request.controlURL#images/delete.gif" name="test" onClick='javascript: this.form.deleteCLUser.value="#callList.usersid#"; return cnfDelete("#CallList.UsersID#","#CallList.lastname#");'></td>

or this?

<input type="image" value="#CallList.usersID#" src="#request.controlURL#images/delete.gif" name="test" onClick="javascript: this.form.deleteCLUser.value=escape('#callList.usersid#'); return cnfDelete(escape('#CallList.UsersID#'),escape('#CallList.lastname#'));"></td>
replace single quote with escape character

like..
from
O'Brien
to
O\'Brien
I can't change whats' coming from the database.
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.value='90064'; return cnfDelete(
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.value='89281'; return cnfDelete(89281,`Polking`);
looks like you are using coldfusion..
then try this

<input type="image" value="#CallList.usersID#" src="#request.controlURL#images/delete.gif" name="test" onClick="javascript: this.form.deleteCLUser.value=escape('#callList.usersid#'); return cnfDelete('#replace(CallList.UsersID,"'","\'","all")#','#replace(CallList.lastname,"'","\'","all")#');"></td>
I' getting "invalid CFML construct...".

<input type="image" value="#CallList.usersID#" src="#request.controlURL#images/delete.gif" name="test" onClick="javascript: this.form.deleteCLUser.value='#callList.usersid#'; return cnfDelete(#CallList.UsersID#,#REreplace(CallList.lastname, '[^a-zA-Z0-9]', '\','all'));"></td>
try with just replace function..

return cnfDelete('#CallList.UsersID#','#replace(CallList.lastname, "'","\'","all")#');
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.value='27159'; return cnfDelete(27159,O\\Brien);
...........................................................................................................^

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....
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
<input type="image" value="#CallList.usersID#" src="#request.controlURL#images/delete.gif" name="test" onClick="javascript: this.form.deleteCLUser.value='#callList.usersid#'; return cnfDelete(#CallList.UsersID#,#REreplace(CallList.lastname, '[^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;
      }
      }
ASKER CERTIFIED SOLUTION
Avatar of Sudhindra A N
Sudhindra A N
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That did it.  Live and learn.  Thanks.
Great response. Patience.
You wouldn't want to look at my cfajaxproxy question would you?
please post...
I will back in 20 to 30 mins..