I have a php function that outputs a form with button (with post) to download a pdf of the table on the previous page. For some reason, I get weird results if I try to use double quotes, but single quotes in the string declaration work ok (except when I try to feed the butter to js innerhtml).
This works:
$form = '<form action="../php/pdf_and_die.php" method="POST" target="_blank">';
$form .= '<input type="hidden" name="table" value="'.$table.'">';
// more lines here
$form .= '<input type="hidden" name="page" value="portrait">';
$form .= '<input type="submit" value=" '.$button_name.' " class="button"></form>';
But this doesn't:
$form = "<form action='../php/pdf_and_die.php' method='POST' target='_blank'>";
$form .= "<input type='hidden' name='table' value='{$table}'>";
// more lines here
$form .= "<input type='submit' value='{$button_name} ' class='button'></form>";
When I try to do the second way with double quotes, the table is displayed before the button. screenshot with double quotes
Shouldn't single/double quotes be mostly the same as far as php and html are concerned, as long as they're used consistently? (barring differences like variables in strings like "foo{$bar}").
This wouldn't be a problem and I would just go with the working single quotes for the string declaration inside the php function, except that on another page, I have a pulldown menu with onclick and a js function that replaces one of these buttons for another based on the academic session the user chooses, and innerhtml doesn't seem to like the single quote (double quotes inside) option. screenshots
On the page that displays the button: (abbreviated for readability)
<?php
foreach ($sessions as $session) {
// string of attendance table
$session_table = get_class_attn_table($course, $acad_year, $session);
// get_pdf_form_button returns a string
$attn_button = get_pdf_form_button($session_table);
// add the output html to the array as a string
$sessions_text[] = $attn_button;
}
?>
<script type="text/javascript">
function toggle_session() {
var x = "" + document.getElementById("session_select").value;
var session1_text = "<?php echo $sessions_text[0];?>";
var session2_text = "<?php echo $sessions_text[1];?>";
if (x == "1") {
document.getElementById("change_session").innerHTML = session1_text;
}
else if (x == "2") {
document.getElementById("change_session").innerHTML = session2_text;
}
}
</script>
<select id="session_select" onchange="toggle_session()">
<option selected value="">Select...</option>
<option value="1">1</option>
<option value="2">2</option>
</select>
I'm pretty new to php and js, so maybe I missed something simple.