?
Solved

JavaScript function call isn't working. Code is attached

Posted on 2012-04-12
3
Medium Priority
?
331 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
[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
3 Comments
 
LVL 23

Assisted Solution

by:basicinstinct
basicinstinct earned 400 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 1600 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

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!

Question has a verified solution.

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

When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
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.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Suggested Courses

765 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