Jul 20, 2008

Javascript And Php

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > PHP Programming

free web hosting

Javascript And Php

adly3000
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

Reply

moldboy
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.

Reply

kvkv
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'];


Reply

adly3000
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?

Reply

kvkv
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.

 

 

 


Reply

adly3000
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";

Reply

moldboy
Sorry, I'm not that good with javascript, would you mind sharing what it's doing.

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:


Searching Video's for javascript, php
advertisement



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