Need help sending data from a table in html in a php file sending to a javascript script with parameters from php
?>
<form action="http://<?=$_SERVER["SERVER_NAME"]?>/index.php/search" method="GET" name="multiform">
<input type="submit" value="Back">
<?
This is one of the items in my table
echo "<td class=\"cent\"> <input type=\"checkbox\" name=\"rids[]\" value=\"{$reportdate}\"> </td>";
Here I am creating the button to be 'sent' to the javascript function - However I want to be able to send multiple items and I want to be able to send variables from PHP
echo"<input type='submit' value='button text' onclick='return view_submit(650,'$reportGarb');' /> ";
These are the items that need to be sent through to the next page - they should be filled out in the javascript function
echo "<input type='hidden' name='edit' value='999'>";
echo "<input type='hidden' name='garcom' value='1'>";
echo "</form>";
This is the function I call from my form submit - the second paramater doesnt get set
<script>
function view_submit(subtype,garcom)
{
if (has_a_check(document.multiform["rids[]"]) == false)
{
alert("You must select some items!");
return false;
}
document.multiform.action='http://<?= $_SERVER["SERVER_NAME"]?>/index.php/search';
document.multiform.method='GET';
document.multiform["edit"].value = subtype;
document.multiform["garcom"].value = garcom;
return true;
}
</script>
What I am seeing is a URL like this
"..com/search?rids%5B%5D=2013-05-01&edit=999&garcom=1
So Is the way I am doing this the best way to do it, and why is the second parameter not being set to my variable that I pass to the js?
If I remove the second parameter the edit becomes 650
Get rid of the double quotes. Magic quotes are the worst idea php ever had. They are phasing them out because they realized this an it only creates coding nightmares.
CHANGE
echo "<input type='submit' value='button text' onclick='return view_submit(650,'$reportGarb');' /> ";
TO
echo '<input type="submit" value="button text" onclick="return view_submit(650, "' . $reportGarb . '");" />';
OR BETTER YET
<input type="submit" value="button text" onclick="return view_submit(650, "<?php echo $reportGarb ?>");" />