I, I have a Php script I made to generate a drop down list of dates.
I use Javascript to open a new url with php variables in it when an element is selected in this list.
I use <?php echo $variable ;?> in a window.location function.
When the new URL is generated, the echo won't add the attribute value in it.
My code is :
I use this snippet in my page : [wbcr_php_snippet id="929" variable="wp_wpdatatable_7" id_table="21"]
You can see in the attached images the generated URL and the correct URL if it worked as I want.
I tried to put an echo $variable in the script and it returned the correct value "wp_wpdatatable_7".
I tried replacing the attribute "variable" by an other variable in the Javascript, I defined it at the start of the script : $var_table = "wp_wpdatatable_7";
It generated the correct URL.
I don't understand why the echo in the javascript won't work with the attribute but work with a standard php variable.
Any help would by wonderfull.
Best Regards,
Benoit COUTINEAU
I use Javascript to open a new url with php variables in it when an element is selected in this list.
I use <?php echo $variable ;?> in a window.location function.
When the new URL is generated, the echo won't add the attribute value in it.
My code is :
PHP:
<?php
$hostname="XXX";
$db="XXX";
$Username="XXX";
$Password="XXX";
$conn=new PDO("mysql:host=$hostname;dbname=$db",$Username,$Password);
$sql= "SELECT CONCAT(display_header,' - ',orig_header) AS date_list FROM wp_wpdatatables_columns WHERE display_header NOT LIKE 'Date%' AND orig_header LIKE 'date%' AND table_id = $id_table";
try{
$stmt=$conn->prepare($sql);
$stmt->execute();
$results=$stmt->fetchAll();
}
catch(Exception $ex){
echo($ex -> getMessage());
}
?>
<html>
<center>
<label>
<select name="select1" id="select1">
<option>-- Sélectionner la date --</option>
<?php foreach ($results as $output) {?>
<option><?php echo $output["date_list"];?></option>
<?php }?
</select>
</label>
</center>
<script type="text/javascript">
var urlmenu = document.getElementById( 'select1' );
urlmenu.onchange = function() {
window.location = ( "/listes-XXX/?table=<?php echo $variable ;?>&date=" + this.options[ this.selectedIndex ].value );
};
</script>
</html>
You can see in the attached images the generated URL and the correct URL if it worked as I want.
I tried to put an echo $variable in the script and it returned the correct value "wp_wpdatatable_7".
I tried replacing the attribute "variable" by an other variable in the Javascript, I defined it at the start of the script : $var_table = "wp_wpdatatable_7";
It generated the correct URL.
I don't understand why the echo in the javascript won't work with the attribute but work with a standard php variable.
Any help would by wonderfull.
Best Regards,
Benoit COUTINEAU
Attachments
-
10.2 KB Views: 61
-
10.5 KB Views: 52
-
10.6 KB Views: 74