Implement an Ajax-based survey program

Source: Internet
Author: User

<Html>
<Head>
<Title> vote </title>
<META http-equiv = Content-Language content = zh-cn>
<META http-equiv = Content-Type content = "text/html; charset = gb2312">
<Style type = "text/css">
<! --
. Poll {font-size: 10pt; display: block}
. Pollresult {font-size: 12pt; display: none}
-->
</Style>
<? Php (as the mainstream development language)
Include_once ("server1.server. php (as the mainstream development language)"); # servidor para Xajax (static dynamic website)
$ Xajax (static dynamic website)-> printJavascript ();
?>

</Head>
<Body>

<Script language = javascript>
Function back (){
Document. getElementById (poll). style. display = block;
Document. getElementById (pollresult). style. display = none;
Document. getElementById (pollresult). innerHTML =;
}
</Script>
<Div id = pollresult class = pollresult>

</Div>


<? Php (as the mainstream development language)


Global $ db;

$ Poll = $ db-> getRow ("select * from TBL_POLL order by poll_id desc limit 1 ");
$ Poll_id = $ poll ["poll_id"];
$ Pollitems = $ db-> getAll ("select * from TBL_POLLITEM where poll_id = $ poll_id ");
?>
<Div id = poll class = poll>
<Form id = "pollForm" action = "javascript: void (null);" onsubmit = "onSubmit ();">
<? Php (as the mainstream development language) echo $ poll ["title"];?> <Br>
<? Php (as the mainstream development language) for ($ I = 0, $ count = count ($ pollitems); $ I <$ count; $ I ++) {?>
<Input type = "radio" style = "background-color: # CCCCCC;" name = "pollitem" value = "<? Php (as the mainstream development language) echo $ pollitems [$ I] [pollitem_id]?> "> <? Php (as the mainstream development language) echo $ pollitems [$ I] [content]?> <Br>
<? Php (as the mainstream development language)}?>
<Input type = "hidden" name = "poll_id" value = "<? Php (as the mainstream development language) echo $ poll_id;?> ">
<Input type = "submit" value = "enter">
</Form>
<Script language = javascript>
Function onSubmit (){
Xajax (static dynamic website) _ poll (xajax (static dynamic website). getFormValues ("pollForm "));
Document. getElementById (poll). style. display = none;
Document. getElementById (pollresult). style. display = block;
}
</Script>
</Div>

</Body>
</Html>

Server

Function poll ($ formData ){
Global $ db;
$ Tmp = "";
$ ObjResponse = new xajax (static dynamic website) Response ();

$ Poll_id = $ formData [poll_id];
$ Pollitem_id = $ formData [pollitem];

If ($ pollitem_id> 0 & $ poll_id> 0 ){
$ Db-> query ("update". TBL_POLLITEM. "set count = count + 1 where pollitem_id = $ pollitem_id ");
}

$ Poll = $ db-> getRow ("select * from TBL_POLL where poll_id = $ poll_id ");
$ Pollitems = $ db-> getAll ("select * from TBL_POLLITEM where poll_id = $ poll_id ");


$ Tmp. = "<div align = center>". $ poll ["title"]. "</div> <br> ";
For ($ I = 0, $ count = count ($ pollitems); $ I <$ count; $ I ++ ){
$ Tmp. = "<div align = left> ". $ pollitems [$ I] [content]. ":". $ pollitems [$ I] [count]. "</div> ";

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.