need help passing php varible into javascript generated url
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!!!
Code:
<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>
PHP Code:
////////// 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 ///////////
//
?>
Re: need help passing php varible into javascript generated url
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?
Re: need help passing php varible into javascript generated url
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.
Re: need help passing php varible into javascript generated url
Sounds like you should be implementing AJAX.
Re: need help passing php varible into javascript generated url
Quote:
Originally Posted by
PeejAvery
Sounds like you should be implementing AJAX.
do you have an example to how to use ajax with this example?
Re: need help passing php varible into javascript generated url
Not with your exact code. AJAX is very simple. Start here....