Simple jquery passing a parameter via a link

Posted on 2014-07-16
Last Modified: 2015-04-30
Hi all,
im new to jquery.

I have this window that opens a modal:

How can I I pass a variable to the page that is opened from the link, so for example it opens ajax.html?id=[variable]

in normal js I would have just included it in the function call, like openmodal(12), but not sure how to do it in jquery

Question by:Stephen Forlance
    LVL 58

    Assisted Solution

    You can add it directly in the js

    $.get('ajax.html?id=somevar', function(data){

    ...unless there is more to it...?

    Author Comment

    by:Stephen Forlance
    Hi Gary, but how do I set somevar within the link?
    LVL 58

    Expert Comment

    Just change somevar to whatever it should be.

    Author Comment

    by:Stephen Forlance
    I think I need to explain what Im trying to do.

    On the HTML there would be multiple links, each with a different variable.
    Normally in JS I would do something like

    <a href=#" onclick="somefunction(12)">a</a>

    So the function somefunction would receive the variable 12, which I could then use to call the correct page.

    How can I do this with jquery?
    LVL 58

    Accepted Solution

    To the link add something like this


    In the jquery use

    $.get('ajax.html?id='+$(this).data("id"), function(data){

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
    Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

    728 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

    17 Experts available now in Live!

    Get 1:1 Help Now