[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

need help with simple problem - javascript

Posted on 2011-09-12
21
Medium Priority
?
240 Views
Last Modified: 2012-05-12
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
Comment
Question by:lantervj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 12
  • 8
21 Comments
 
LVL 13

Expert Comment

by:ansudhindra
ID: 36521472
try with this..
var deletemessage = 'Are you sure you want to delete this record?  '+userid+' '+lastname;
0
 

Author Comment

by:lantervj
ID: 36521505
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
 
LVL 13

Expert Comment

by:ansudhindra
ID: 36521510
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
Industry Leaders: 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!

 

Author Comment

by:lantervj
ID: 36521551
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
 
LVL 40

Expert Comment

by:Gurvinder Pal Singh
ID: 36521589
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
 
LVL 13

Expert Comment

by:ansudhindra
ID: 36521596
replace single quote with escape character

like..
from
O'Brien
to
O\'Brien
0
 

Author Comment

by:lantervj
ID: 36521602
I can't change whats' coming from the database.
0
 

Author Comment

by:lantervj
ID: 36521609
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
 

Author Comment

by:lantervj
ID: 36521620
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
 
LVL 13

Expert Comment

by:ansudhindra
ID: 36521623
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
 

Author Comment

by:lantervj
ID: 36521660
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
 
LVL 13

Expert Comment

by:ansudhindra
ID: 36521667
try with just replace function..

return cnfDelete('#CallList.UsersID#','#replace(CallList.lastname, "'","\'","all")#');
0
 

Author Comment

by:lantervj
ID: 36521680
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
 
LVL 13

Expert Comment

by:ansudhindra
ID: 36521683
did you copied my code above ?? or please post the code...
I see that single quotes are missing for arguments....
0
 

Author Comment

by:lantervj
ID: 36521693
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
 

Author Comment

by:lantervj
ID: 36521701
<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
 
LVL 13

Accepted Solution

by:
ansudhindra earned 2000 total points
ID: 36521702
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
 

Author Comment

by:lantervj
ID: 36521717
That did it.  Live and learn.  Thanks.
0
 

Author Closing Comment

by:lantervj
ID: 36521720
Great response. Patience.
0
 

Author Comment

by:lantervj
ID: 36521723
You wouldn't want to look at my cfajaxproxy question would you?
0
 
LVL 13

Expert Comment

by:ansudhindra
ID: 36521727
please post...
I will back in 20 to 30 mins..
0

Featured Post

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s time for spooky stories and consuming way too much sugar, including the many treats we’ve whipped for you in the world of tech. Check it out!
Here in this article, you will get a step by step guidance on how to restore an Exchange database to a recovery database. Get a brief on Recovery Database and how it can be used to restore Exchange database in this section!
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question