noobstar Posted October 2, 2007 Share Posted October 2, 2007 Hi, im was fiddling with the prompt to try and somehow when a user clicks on a button would ask for his/her name and then display it however, it didn't work out but it did work this way without a function: <script language="JavaScript"> var name = prompt('hello', ''); </script> <?php $hello = "<script language=JavaScript>document.write(name);</script>"; echo "$hello<br/>"; ?> My question is how could i make this work when someone clicks a button instead of it prompting the user when ever he/she loads the page? I tried this but I am sure its something to do with the variable not being passed because its only used within the function and its not usable for some reason outside it. How could i go about making the variable available for any outside functions or other scripts ? <script language="JavaScript"> function prompter(name) { name = prompt('hello', ''); } </script> <?php $hello = "<script language=JavaScript>document.write(name);</script>"; echo "$hello<br/>"; ?> <input type="button" onClick="prompter();"> Quote Link to comment https://forums.phpfreaks.com/topic/71461-solved-javascript-function-problem/ Share on other sites More sharing options...
RichardRotterdam Posted October 2, 2007 Share Posted October 2, 2007 what exactly do you want your code to do its a bit vague to me Quote Link to comment https://forums.phpfreaks.com/topic/71461-solved-javascript-function-problem/#findComment-359775 Share on other sites More sharing options...
emehrkay Posted October 2, 2007 Share Posted October 2, 2007 set an area to receive the name from the prompt so where ever (one location) you want the name to show up put this <span id="prompt_name"></span> in your prompt function do var name = prompt('Text', ''); document.getElementById('prompt_name').innerHTML = name; Quote Link to comment https://forums.phpfreaks.com/topic/71461-solved-javascript-function-problem/#findComment-359792 Share on other sites More sharing options...
noobstar Posted October 2, 2007 Author Share Posted October 2, 2007 Thanks for the reply emehrkay your code worked nicely!! Quote Link to comment https://forums.phpfreaks.com/topic/71461-solved-javascript-function-problem/#findComment-359885 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.