Get variable from JavaScript in PHP |
Get variable from JavaScript in PHP |
FrostTaco |
May 6 2016, 09:36 PM
Post
#1
|
Member Group: Members Posts: 47 Joined: 26-April 16 Member No.: 24,193 |
Hi guys, so what i need todo is make a javascript popup, with a textbox where a player can type something. I then need to write what the player typed into a json file(which i know how todo). All i need to know how todo is get the value of prompt("Please enter your trade link", "TradeLink"); in php. If this is not possible, then could i prompt the player in php?
|
Christian J |
May 7 2016, 05:11 AM
Post
#2
|
. Group: WDG Moderators Posts: 9,630 Joined: 10-August 06 Member No.: 7 |
A javascript popup and prompt is not the same thing. If it's a popup containing a real page, then you could let a form in that page submit to the PHP script.
|
Frederiek |
May 7 2016, 07:22 AM
Post
#3
|
Programming Fanatic Group: Members Posts: 5,146 Joined: 23-August 06 From: Europe Member No.: 9 |
Or search for "pass javascript prompt value to php".
|
FrostTaco |
May 7 2016, 09:50 AM
Post
#4
|
Member Group: Members Posts: 47 Joined: 26-April 16 Member No.: 24,193 |
Or search for "pass javascript prompt value to php". Thanks Will tell you if it worked. QUOTE A javascript popup and prompt is not the same thing. If it's a popup containing a real page, then you could let a form in that page submit to the PHP script. Ahh, sorry about that, I meant prompt. EDIT: I just noticed a problem, the JavaScript runs on page load, and when I click the text(which should make the prompt popup). However, the prompt does not show up on page load, so it causes several problems(The function with the prompt shouldn't even run on page load!). Any idea to fix this? This post has been edited by FrostTaco: May 7 2016, 10:07 AM |
Christian J |
May 7 2016, 10:28 AM
Post
#5
|
. Group: WDG Moderators Posts: 9,630 Joined: 10-August 06 Member No.: 7 |
the prompt does not show up on page load, so it causes several problems(The function with the prompt shouldn't even run on page load!). Should it or should it not run on page load? QUOTE Any idea to fix this? Could you post a link or code sample showing the problem? |
FrostTaco |
May 7 2016, 10:55 AM
Post
#6
|
Member Group: Members Posts: 47 Joined: 26-April 16 Member No.: 24,193 |
the prompt does not show up on page load, so it causes several problems(The function with the prompt shouldn't even run on page load!). Should it or should it not run on page load? QUOTE Any idea to fix this? Could you post a link or code sample showing the problem? It should not run on page load. CODE document.getElementById('crefer').onclick = function() { The code inside i am working on, but the file is created on page load, and then is edited onclick...var rlink = prompt("Your referal link is http://corndog.corticalcafe.com/?", "ABCYXZ"); if(rlink != null){ <?php $steam64 = str_replace("http://steamcommunity.com/openid/id", "", $_SESSION['FrostyTaco']); $_SESSION['steam_name'] = $content['response']['players'][0]['personaname']; $name = $_SESSION['steam_name']; $referbuffer = fopen("cache/refer.json", "w+"); $rlink = ""; $arr = array("$name" => "$rlink"); fwrite($referbuffer, json_encode($arr)); fclose($referbuffer); ?> } } |
Christian J |
May 7 2016, 11:24 AM
Post
#7
|
. Group: WDG Moderators Posts: 9,630 Joined: 10-August 06 Member No.: 7 |
That's the same code snippet as in http://forums.htmlhelp.com/index.php?showtopic=43884, so maybe we should continue the javascript discussion there.
|
FrostTaco |
May 7 2016, 08:27 PM
Post
#8
|
Member Group: Members Posts: 47 Joined: 26-April 16 Member No.: 24,193 |
That's the same code snippet as in http://forums.htmlhelp.com/index.php?showtopic=43884, so maybe we should continue the javascript discussion there. ok, totally forgot that post was their xD |
FrostTaco |
May 9 2016, 09:02 PM
Post
#9
|
Member Group: Members Posts: 47 Joined: 26-April 16 Member No.: 24,193 |
|
Christian J |
May 10 2016, 06:20 AM
Post
#10
|
. Group: WDG Moderators Posts: 9,630 Joined: 10-August 06 Member No.: 7 |
I don't think it gets much easier than that. If you don't want the main page's URL to change, you might load the URL with the querystring in a hidden iframe instead.
|
FrostTaco |
May 10 2016, 11:01 AM
Post
#11
|
Member Group: Members Posts: 47 Joined: 26-April 16 Member No.: 24,193 |
I don't think it gets much easier than that. If you don't want the main page's URL to change, you might load the URL with the querystring in a hidden iframe instead. Sorry if this is a dumb question, but i'm not to familiar with iframes. How do I use php to get the querystring in an iframe? |
Christian J |
May 10 2016, 01:24 PM
Post
#12
|
. Group: WDG Moderators Posts: 9,630 Joined: 10-August 06 Member No.: 7 |
The framed page contains the PHP script. When the parent page requests the framed page from the server, the PHP script in the framed page will run and you can get the framed page's querystring with $_GET as usual.
|
FrostTaco |
May 10 2016, 01:38 PM
Post
#13
|
Member Group: Members Posts: 47 Joined: 26-April 16 Member No.: 24,193 |
The framed page contains the PHP script. When the parent page requests the framed page from the server, the PHP script in the framed page will run and you can get the framed page's querystring with $_GET as usual. I think I understand it now, so I have to make a new page, in the frame I open that page(but hidden), the page contains in PHP script, and that page makes the file? |
Christian J |
May 10 2016, 02:51 PM
Post
#14
|
. Group: WDG Moderators Posts: 9,630 Joined: 10-August 06 Member No.: 7 |
|
FrostTaco |
May 10 2016, 03:11 PM
Post
#15
|
Member Group: Members Posts: 47 Joined: 26-April 16 Member No.: 24,193 |
I think I understand it now, so I have to make a new page, in the frame I open that page(but hidden), the page contains in PHP script, and that page makes the file? Yes (I assume "the file" is the json file). Thanks, it works, just one thing. So when I edit the json file through the website, I also have part of the json file outputted on the site. So I need to refresh the page(not the iframe) after it changed the file, how can I make sure the file is changed before I refresh? |
FrostTaco |
May 10 2016, 05:03 PM
Post
#16
|
Member Group: Members Posts: 47 Joined: 26-April 16 Member No.: 24,193 |
I think I understand it now, so I have to make a new page, in the frame I open that page(but hidden), the page contains in PHP script, and that page makes the file? Yes (I assume "the file" is the json file). Thanks, it works, just one thing. So when I edit the json file through the website, I also have part of the json file outputted on the site. So I need to refresh the page(not the iframe) after it changed the file, how can I make sure the file is changed before I refresh? Nevermind, got it working. |
Lo-Fi Version | Time is now: 28th March 2024 - 09:10 AM |