hi,
i'm a newbie programmer and i just built a website with a poll. the page is completely in html and linked to the php script processing the poll result in the action attribute of the form tag. my problem is the results of the poll comes up in a new page when the user hits the submit button, but i need the results of the poll to appear just under the poll questions on the same page. can anybody help me with that?
showing results in the same page
Moderator: General Moderators
-
cali_dotcom
- Forum Commoner
- Posts: 49
- Joined: Fri Aug 22, 2008 7:28 pm
- Location: Rancho Cucamonga, CA
Re: showing results in the same page
yes you can on the form tag....
this will call the same page.. and whatever value is going to be passed will also be on the same page.. but remember computer starts processing codes from TOP to BOTTOM.. so i suggest you process the passed variables before displaying any HTML pages.
Code: Select all
<form action='<?php echo $_SERVER["PHP_SELF"]?>'>
Re: showing results in the same page
You can do that using AJAX, but not by just calling a PHP script in the usual manner. AJAX is the use of Javascript (therefore, it can respond to a user's actions) to call a PHP script in asynchronous mode, which will then return only data, not a whole new page to the browser. The Javascript must include a function that "listens" for the returned data and (usually) replaces the innerHtml property of some HTML element. It's not that hard to do, but the code is a little confusing at first. Check out:cali_dotcom wrote:hi,
i'm a newbie programmer and i just built a website with a poll. the page is completely in html and linked to the php script processing the poll result in the action attribute of the form tag. my problem is the results of the poll comes up in a new page when the user hits the submit button, but i need the results of the poll to appear just under the poll questions on the same page. can anybody help me with that?
http://www.w3schools.com/Ajax/Default.Asp
http://www.xul.fr/en-xml-ajax.html
http://www.tizag.com/ajaxTutorial/
Re: showing results in the same page
oh wtf? we're talking about ajax here? cause you said you're newbie lol.. ajax isn't for newbs but yeah you can start learning it if you have strong foundation with javascripting and phps
- The_Anomaly
- Forum Contributor
- Posts: 196
- Joined: Fri Aug 08, 2008 4:56 pm
- Location: Tirana, Albania
Re: showing results in the same page
This javascript stuff is probably the best way to do it, but not necessary if you don't need/want asynchronous pages. It's probably worth looking into, just because of how professional and seamless it is, but not necessary.califdon wrote:You can do that using AJAX, but not by just calling a PHP script in the usual manner. AJAX is the use of Javascript (therefore, it can respond to a user's actions) to call a PHP script in asynchronous mode, which will then return only data, not a whole new page to the browser. The Javascript must include a function that "listens" for the returned data and (usually) replaces the innerHtml property of some HTML element. It's not that hard to do, but the code is a little confusing at first. Check out:cali_dotcom wrote:hi,
i'm a newbie programmer and i just built a website with a poll. the page is completely in html and linked to the php script processing the poll result in the action attribute of the form tag. my problem is the results of the poll comes up in a new page when the user hits the submit button, but i need the results of the poll to appear just under the poll questions on the same page. can anybody help me with that?
http://www.w3schools.com/Ajax/Default.Asp
http://www.xul.fr/en-xml-ajax.html
http://www.tizag.com/ajaxTutorial/
You could also do this by using a conditional statement based on whether the user submitted a form. i.e:
Code: Select all
<?php
if(isset($_POST['Submit']){
displayResults();
}
?>
Re: showing results in the same page
The OP said that he wants to avoid a second page load. That's why it involves AJAX.