Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I need to get variables from a html link, this is the link and when it is clicked it shows the popup window.

<a href='#' onclick=\"show('poruka');var idporuke=$porid; \">Pogledaj<a>

And I have var idporuke=$porid; which is working like a charm. But I need to pass that variable to php script? I can't use GET or POST methods.

share|improve this question
1  
If you can't use the "GET" or "POST" methods to send you data you are SOL. –  secretformula Aug 20 '11 at 12:53
 
I'm afraid you're going to have to, or some form of AJAX –  benhowdle89 Aug 20 '11 at 12:53
 
How can i do it ? ... I can use "GET" and "POST" but how do i do it with link ? .. Btw. When i use post and get the popup window dissapear :S –  haris Aug 20 '11 at 12:56
 
@haris: Can you use jQuery ?? –  NAVEED Aug 20 '11 at 12:57
1  
You have to use Javascript's XMLHTTPRequest object to create a request (GET or POST) and send it. It will load without refreshing the current page. Or, you could use an iframe HTML element. –  RSully Aug 20 '11 at 12:59
show 6 more comments

3 Answers

html

<img src="about:blank" id="fake_request" style="position:absolute; top: -20px;left:-20px;width:1px;height:1px;" />

<a href='#' onclick=\"show('poruka');var idporuke=$porid; document.getElementById('fake_request').src='/myPhpScript.php?idporuke='+idporuke+';">Pogledaj<a>

something like this

share|improve this answer
 
I would not consider this very elegant, an iframe would do just as well, plus it is more correct for a request –  RSully Aug 22 '11 at 1:34
add comment

Try this:

<a href='#' onclick="show('poruka');var idporuke=$porid;">Pogledaj<a>

Your welcome!

–SilverHorn

share|improve this answer
add comment

It sounds like you are trying to pass a browser side variable to a server side script. PHP does all of its processing, then the HTML/Javascript takes over. The only methods you have for passing a variable through from browser to server are via either a page refresh or Javascript AJAX. If you absolutely cannot use POST or GET, you could use Cookies (http://techpatterns.com/downloads/javascript_cookies.php) or Sessions...although I am pretty sure sessions are not supported in Javascript. I would recommend using POST or GET depending on the variable size - Cookies come with a lot of limitations and conditions.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.