LOLcayter Posted January 14, 2007 Share Posted January 14, 2007 I have an HTML form that I've used to send data to a PHP script. I know this must be elementary, but how can I now get the output of said script and immediately display it on my webpage? It would be like What is the answer to the universe?Form 1: DataForm 2: Data"Submit"The answer is: _____to (when you click submit)What is the answer to the universe?Form 1: DataForm 2: Data"SubmitThe answer is: 42!!!!But this must be without refreshing the page or anything, just having it show up. I've tried every type of include I can think of and it doesn't do anything... Any help would be greatly appreciated. Link to comment Share on other sites More sharing options...
boen_robot Posted January 14, 2007 Share Posted January 14, 2007 The only way you can do this without refreshing is JavaScript. But this means that the answer would be inside the source of the page, but also, that users with JavaScript disabled won't be able to view the answers.There are some workarounds for both issues.You can use xmlhttprequest() a.k.a. AJAX to fetch the answer from the server, but the form itself will have to be composed in another form.You can use JavaScript to disable the submit button for the PHP file and/or use alternative button for the AJAX fetch. When JS is disabled, the submit button won't be hidden and/or the other won't be available. This will force the user to refresh the page, but would at least enable him/her to view the answers. Link to comment Share on other sites More sharing options...
LOLcayter Posted January 14, 2007 Author Share Posted January 14, 2007 Ok, but I was wondering, what if the answer needs to be generated because of what they say? Like what if I had then put in 3+5, it would need to show 8, but if they put in 6+6, it would need to show 12. Link to comment Share on other sites More sharing options...
justsomeguy Posted January 15, 2007 Share Posted January 15, 2007 For simple math, you can use Javascript. If you need the power of PHP, then you have to use something like AJAX as boen suggested. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now