Solved

jQuery UI how to get rid of inline function

Posted on 2011-02-22
3
492 Views
Last Modified: 2012-05-11
Experts,

Environment: jQuery UI; Dot Net MVC

I'm using an inline function to access some data via json. How do I call the function from the onclick event instead of having it inline. Multiple links or buttons will need to call this function and send in a value?

I've attached the inline jQuery function. "addressID" is what I'll need to pass in.

Thanks!
Bob


$.post("/Report/Address/" + addressId, "",function(data){$("#addressId").val(data.AddressId);$("#street").val(data.Street);$("#city").val(data.City);$("#state").val(data.State);$("#zip").val(data.Zip);}, "json");

Open in new window

0
Comment
Question by:lateapex
  • 2
3 Comments
 
LVL 40

Expert Comment

by:gurvinder372
ID: 34958392
why don't you re factor it out in a method

$.post("/Report/Address/" + addressId, "", inlineFunctionReafactored);

function inlineFunctionReafactored(data)
{
}
0
 
LVL 40

Accepted Solution

by:
gurvinder372 earned 500 total points
ID: 34958403
now this inlineFunctionReafactored method can be called at onclick etc

or even this can be tried

$.post("/Report/Address/" + addressId, "",function(data){inlineFunctionReafactored(data)}, "json");

$.post("/Report/Address/" + addressId, "", );

function inlineFunctionReafactored(data)
{
$("#addressId").val(data.AddressId);
$("#street").val(data.Street);
$("#city").val(data.City);
$("#state").val(data.State);
$("#zip").val(data.Zip);
}
0
 

Author Closing Comment

by:lateapex
ID: 34961914
Thanks!
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
I need help displaying 2 models in one view in my MVC.Net application with C# code behind 5 51
ASP.NET 5 Templates 2 78
ASP.NET MVC 2 31
List<PaisEntity> - show some 1 24
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

803 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