Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 60
  • Last Modified:

Simple jquery passing a parameter via a link

Hi all,
im new to jquery.

I have this window that opens a modal:

http://bit.ly/1nwlkVW


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

Thanks,
0
Stephen Forlance
Asked:
Stephen Forlance
  • 3
  • 2
2 Solutions
 
GaryCommented:
You can add it directly in the js

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

...unless there is more to it...?
0
 
Stephen ForlanceAuthor Commented:
Hi Gary, but how do I set somevar within the link?
0
 
GaryCommented:
Just change somevar to whatever it should be.
0
 
Stephen ForlanceAuthor Commented:
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?
0
 
GaryCommented:
To the link add something like this

data-id="2"

In the jquery use

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

Featured Post

Independent Software Vendors: 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!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now