• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 349
  • Last Modified:

JavaScript function call isn't working. Code is attached

I have attached the code.

I need to call a function inside javascript code that looks like a href function. I am needing to do this to troubleshoot some existing client code.

I need this call to work but currently it isn't working:

return 'javascript:functionToProcessGenericObject("' + genericObject.firstName + '", "' + genericObject.lastName + '", "' + genericObject.amountDue + '", "' + genericObject.dueDate + '","' + genericObject.Number + '");';

I'm more familiar with this type of a call. This works.
return functionToProcessGenericObject(genericObject.firstName, genericObject.lastName, genericObject.amountDue, genericObject.dueDate, genericObject.Number);

Cheers,
alex
Broken.html
0
alexmac05
Asked:
alexmac05
2 Solutions
 
basicinstinctCommented:
well the "broken" code is returning a string...
to execute a string you need to call eval
you could also call "new Function(...)" but that's bad too.

but this is the wrong way to do any of this... you should not use eval (bad practice, bad performance, not compatible with strict mode).
whoever wrote that code was confused.

why don't you just use the "This works" code if it works...
0
 
Lalit ChandraCommented:
You can use eval() to execute the Statement stored inside the string.. Like below


var m='javascript:functionToProcessGenericObject("Nancy", "Fields", "12.75", "12/12/12","43132")';

eval(m);

But the use of eval can be dangerous, so use with caution.Remember though, that eval is very powerful and quite unsafe. You better be confident that the script you are executing is safe and unmutable by users.

Hope the above info might help you.
0
 
alexmac05Author Commented:
Thank you both. This is just to reproduce another issue that has nothing to do with how this is being called, so this will work. Thanks for the warning about eval, but it will only be for a mock test.

Thank you very much. Both of you, thanks
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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