| | i am designing a poll in which i use javascript, and i need to pass the selected answer in my poll to php variables so how can i do that, any help will be appricated |
|
|
Are you using Radio buttons for your polls? If yes then when you submit the forum then it will submit that information, however if you want to use JS to edit the page ou can do a hidden forum field with the answer then submit it.
It depends on weather you are using a form or not. If you are using a form, in your javascript, you will submit the form. In this case make sure your radiobutton group or checkbox (whatever you use for selecting the choice) is part of the form. If you are not using form, you will have to redirect to the php script in your url with selected choice value as parameter.
In your php script, you can obtain the value from $_REQUEST variable array. For example, if you have radio_1 as one radio button group, you can get the selected value by CODE $sel1=$_REQUEST['radio_1'];
thanks all;
kvkv i understand your words.u mean i should pass the selectd checkbox to the url then identify it by $_request in php!! is that what do you mean? QUOTE(adly3000 @ Feb 1 2006, 03:16 PM) thanks all; kvkv i understand your words.u mean i should pass the selectd checkbox to the url then identify it by $_request in php!! is that what do you mean? Yes. But the easier way is to use a form. Ex: CODE <FORM ACTION="evaluate.php"> <INPUT TYPE=CHECKBOX NAME="sel_1">Answer_1 <INPUT TYPE=CHECKBOX NAME="sel_2">Answer_2 <INPUT TYPE=CHECKBOX NAME="sel_3">Answer_3 <INPUT TYPE=CHECKBOX NAME="sel_4">Answer_4 <INPUT TYPE=SUBMIT> </FORM> This will give you multiple check boxes (4 in this case) with a submit button. When user selects the answer and clicks submit button, it will be submitted to the action script (evaluate.php in above example). You don't have to pass any values in url explicitly, but if the checkbox is selected, the variable will be automatically available in the action script.
sorry my demands needs javascript in code, here is a part of my code:
CODE $pollAnswers .= "<form name=\"poll" . $pollid . "\" method=\"post\">\n"; $pollAnswers .= "<table width=\"100%\" dir=\"rtl\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" bgcolor=\"" . $pollbgcolor . "\">\n"; $num_results2 = mysql_num_rows($result2); if ($num_results2 > 0) { while ($row2 = mysql_fetch_array($result2)) { $pollAnswers .= "<tr>\n"; $pollAnswers .= "<td width=\"5\" align=\"center\"><input type=\"radio\" name=\"sel\" value=\"" . $row2["id"] . "\" onClick=\"document.poll" . $pollid . ".hsel.value='" . $row2["id"] . "';\"></td>\n"; $pollAnswers .= "<td width=\"100%\" align=\"right\" nowrap><font face=\"" . $pollfontface . "\" size=\"" . $pollfontsize . "\" color=\"" . $pollfontcolor . "\" style=\"MARGIN-RIGHT: 5px; MARGIN-LEFT: 0px\">" . $row2["Choice"] . "</font></td>\n"; $pollAnswers .= "</tr>\n"; } $pollAnswers .= "<tr>\n"; $pollAnswers .= "<td height=\"5\" colspan=\"2\" nowrap><spacer type=\"vertical\" height=\"5\"></td>\n"; $pollAnswers .= "</tr>\n"; $pollAnswers .= "<tr>\n"; $pollAnswers .= "<td colspan=\"2\">\n"; $pollAnswers .= "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" bgcolor=\"" . $polltfooterbgcolor . "\">\n"; $pollAnswers .= "<tr>\n"; $pollAnswers .= "<td width=\"50%\" align=\"center\"><input type=\"button\" name=\"submit\" value=\"submit\" onClick=\"openVote('$pollid',document.poll" . $pollid . ".hsel.value)\"></td>\n"; $pollAnswers .= "<td width=\"50%\" align=\"center\"><a href=\"javascript: openResult('$pollid')\"><font face=\"" . $polltfooterfontface . "\" size=\"" . $polltfooterfontsize . "\" color=\"" . $polltfooterfontcolor . "\">view results</font></a></td>\n"; $pollAnswers .= "</tr>\n"; $pollAnswers .= "</table>\n"; $pollAnswers .= "</td>\n"; $pollAnswers .= "</tr>\n"; } $pollAnswers .= "</table>\n"; $pollAnswers .= "<input type=\"hidden\" name=\"hsel\" value=\"\">\n"; $pollAnswers .= "</form>\n";
Sorry, I'm not that good with javascript, would you mind sharing what it's doing.
Similar Topics
Keywords : javascript, php
(2) I have heard that you can build a chat for a website that would display the username, etc, using (1) I am rewriting a Javascript into PHP, but I have two questions: How can I write these functions in Has PHP possibility to do it without JS (7) I have many PHP Books, PHP Bible among others, but no clear description how to build menus (dynamic) Or javascript? (4) I want to make a game similar to the army system or on Omega Gateway, like a text game. Would I use Looking for javascript, php
|
|
![]() Javascript And Php |
| ADD REPLY / Got an Opinion! | Remove these ADs! | RAPID SEARCH! | Free Web Hosting | [X] |
|
Express your Opinions, Thoughts or Contribute more info. to help others. Ask your Doubts & Queries to get answers, So that "Together We can help others!" |
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP. | 500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE |
|