Solved

JavaScript function call isn't working. Code is attached

Posted on 2012-04-12
3
308 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 to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article will show, step by step, how to integrate R code into a R Sweave document
Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

746 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

13 Experts available now in Live!

Get 1:1 Help Now