Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 241
  • Last Modified:

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;
      }
      }
0
lantervj
Asked:
lantervj
  • 12
  • 8
1 Solution
 
ansudhindraCommented:
try with this..
var deletemessage = 'Are you sure you want to delete this record?  '+userid+' '+lastname;
0
 
lantervjAuthor Commented:
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;
      }
      }
0
 
ansudhindraCommented:
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>
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
lantervjAuthor Commented:
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?
0
 
Gurvinder Pal SinghCommented:
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>
0
 
ansudhindraCommented:
replace single quote with escape character

like..
from
O'Brien
to
O\'Brien
0
 
lantervjAuthor Commented:
I can't change whats' coming from the database.
0
 
lantervjAuthor Commented:
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(
0
 
lantervjAuthor Commented:
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`);
0
 
ansudhindraCommented:
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>
0
 
lantervjAuthor Commented:
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>
0
 
ansudhindraCommented:
try with just replace function..

return cnfDelete('#CallList.UsersID#','#replace(CallList.lastname, "'","\'","all")#');
0
 
lantervjAuthor Commented:
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.
0
 
ansudhindraCommented:
did you copied my code above ?? or please post the code...
I see that single quotes are missing for arguments....
0
 
lantervjAuthor Commented:
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
0
 
lantervjAuthor Commented:
<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;
      }
      }
0
 
ansudhindraCommented:
try with 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#','#replace(CallList.lastname, "'","\'","all")#');"></td>
0
 
lantervjAuthor Commented:
That did it.  Live and learn.  Thanks.
0
 
lantervjAuthor Commented:
Great response. Patience.
0
 
lantervjAuthor Commented:
You wouldn't want to look at my cfajaxproxy question would you?
0
 
ansudhindraCommented:
please post...
I will back in 20 to 30 mins..
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 12
  • 8
Tackle projects and never again get stuck behind a technical roadblock.
Join Now