Solved

JavaScript function call isn't working. Code is attached

Posted on 2012-04-12
3
326 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 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

Technology Partners: 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

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
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…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

707 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