Solved

JavaScript function call isn't working. Code is attached

Posted on 2012-04-12
3
317 Views
Last Modified: 2012-04-12
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
Comment
Question by:alexmac05
3 Comments
 
LVL 23

Assisted Solution

by:basicinstinct
basicinstinct earned 100 total points
ID: 37839951
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
 
LVL 7

Accepted Solution

by:
Lalit Chandra earned 400 total points
ID: 37840051
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
 

Author Closing Comment

by:alexmac05
ID: 37840095
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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

828 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