Click to See Complete Forum and Search --> : need help passing php varible into javascript generated url


chineerat
December 11th, 2009, 07:10 PM
Hi!
I am having a problem trying to pass a hidden varibale (php generated) into a javasrcipt event (self.location)shown below.
the values dd3.php?cat=val&appid=appidcheck do show up in the url
eg:
localhost/dd3.php?cat=1&appid=8 appears in the url but the values: cat=1 and appid=8 are not submitted into the actionpage (dd3.php).
my guess is that problem originates from:
"self.location="
is there any javascript which allows the action page to accept the passed variables contained in the url?

thanks in adavnce!!!

<SCRIPT language=JavaScript>
function reload(form)
{

var val=form.cat.options[form.cat.options.selectedIndex].value;
self.location='dd3.php?cat=' + val +'&appid=' + <?php echo $appidcheck;?> ;
}
function reload3(form)
{

var val=form.cat.options[form.cat.options.selectedIndex].value;
var val2=form.subcat.options[form.subcat.options.selectedIndex].value;
self.location='dd3.php?cat=' + val + '&cat3=' + val2 +'&appid=' + <?php echo $appidcheck;?> ;
}

</script>




////////// Starting of first drop downlist /////////

echo "<select name='cat' onchange=\"reload(this.form)\"><option value=''>Select Exam body</option>";
while($noticia2 = mysql_fetch_array($quer2)) {
if($noticia2['BODYID']==@$cat){
echo "<option selected value='$noticia2[BODYID]'>$noticia2[ORGNAME]</option>"."<BR>";}
else{
echo "<option value='$noticia2[BODYID]'>$noticia2[ORGNAME]</option>"; }
}
echo " <input type='hidden' name='appid' id='appid' value='".$appidcheck."'>";
echo "</select>";
////////////////// This will end the first drop down list ///////////

////////// Starting of second drop downlist /////////

echo "<select name='subcat' onchange=\"reload3(this.form)\"><option value=''>Select caterogry</option>";
while($noticia = mysql_fetch_array($quer)) {
if($noticia['PROGRAMID']==@$cat3){echo "<option selected value='$noticia[PROGRAMID]'>$noticia[TITLE]</option>"."<BR>";}
else{echo "<option value='$noticia[PROGRAMID]'>$noticia[TITLE]</option>";}
}
echo " <input type='hidden' name='appid' id='appid' value='".$appidcheck."'>";
echo "</select>";
////////////////// This will end the second drop down list ///////////


////////// Starting of third drop downlist /////////

echo "<select name='subcat3' > <option value=''>Select Course</option>";
while($noticia = mysql_fetch_array($quer3)) {
echo "<option value='$noticia[TITLE]'>$noticia[TITLE]</option>";
}
echo " <input type='hidden' name='appid' id='appid' value='".$appidcheck."'>";
echo "</select>";
////////////////// This will end the third drop down list ///////////

//
?>

PeejAvery
December 12th, 2009, 09:12 AM
You haven't clarified from what pages those two code snippets are from.

With the page that contains that JavaScript...is that page receiving the PHP data in the form of GET or POST? If not, then of course it cannot echo that data. Also...is the variable $appidcheck already set before that JavaScript snippet shows up?

chineerat
December 12th, 2009, 07:29 PM
the javascript is on the same page as the php code. both javascript and php are on the same page (dd3.php)
the javascript is being called as when an "onchange" occurs. not "submit".
the other submitted data are sent as $_POST. this works fine.
yes the variable $appidcheck is already passed before the javascript is called. ( i tested this)

I would like to pass a php variable when a javascript function (page reload) is called, without 'submit'.
can you recommend an alternative method?
i would like this to operate on one page.
thanks.

PeejAvery
December 13th, 2009, 12:27 PM
Sounds like you should be implementing AJAX.

chineerat
December 13th, 2009, 03:19 PM
Sounds like you should be implementing AJAX.

do you have an example to how to use ajax with this example?

PeejAvery
December 13th, 2009, 03:46 PM
Not with your exact code. AJAX is very simple. Start here... (http://w3schools.com/ajax/default.asp).