开发者

PHP get variables from JavaScript onClick (HTML)?

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='#' o开发者_运维知识库nclick=\"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.


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


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.


Try this:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜