Solved

need help with simple problem - javascript

Posted on 2011-09-12
21
237 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:gurvinder372
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 500 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Always backup Domain, SYSVOL etc.using processes according to Microsoft Best Practices. This is meant as a disaster recovery process for small environments that did not implement backup processes and did not run a secondary domain controller that ne…
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

730 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