Solved

need help with simple problem - javascript

Posted on 2011-09-12
21
231 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
  • 12
  • 8
21 Comments
 
LVL 13

Expert Comment

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

Author Comment

by:lantervj
Comment Utility
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
Comment Utility
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
 

Author Comment

by:lantervj
Comment Utility
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
Comment Utility
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
Comment Utility
replace single quote with escape character

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

Author Comment

by:lantervj
Comment Utility
I can't change whats' coming from the database.
0
 

Author Comment

by:lantervj
Comment Utility
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
Comment Utility
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
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:lantervj
Comment Utility
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
Comment Utility
try with just replace function..

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

Author Comment

by:lantervj
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
<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
Comment Utility
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
Comment Utility
That did it.  Live and learn.  Thanks.
0
 

Author Closing Comment

by:lantervj
Comment Utility
Great response. Patience.
0
 

Author Comment

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

Expert Comment

by:ansudhindra
Comment Utility
please post...
I will back in 20 to 30 mins..
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Find out what Office 365 Transport Rules are, how they work and their limitations managing Office 365 signatures.
This video discusses moving either the default database or any database to a new volume.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

771 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now