Reputation: 11
I'm using a Javascript function to submit a form. This function get all data from textbox, set the form action with this data and submit. The problem is that the url of the next page doesn't include faldone
<script type="text/javascript">
function update()
{
var scatola=document.form2.scatola.value;
var faldone=document.getElementById("faldone").innerText;
var fascicolo=document.form2.fascicolo.value;
var desc=document.form2.descrizione.value;
var tipo=document.form2.tipodocumento.value;
var annic=document.form2.annicon.value;
var dal=document.form2.dal.value;
var al="document.form2.al.value;
var esd="document.form2.estremidal.value;
var esa="document.form2.estremial.value;
var vec="document.form2.vecchiasegn.value;
document.form2.action="aggiorna.php?scatola="+scatola+"&faldone="+faldone+"&fascicolo="+fascicolo+"&descrizione="+desc+"&tipod="+tipo+"&annicon="+annic+"&dal="+dal+"&al="+al+"&estremidal="+esd+"&estremial="+esa+"&vecchiasegn="+vec;
document.form2.submit();
}
</script>
<body>
<?php
$conn=mysqli_connect("localhost","root","","barcode");
$barcode=$_GET["codice"];
$s="SELECT * from faldoni where faldone like '%$barcode%'";
$q=mysqli_Query($conn,$s);?>
<form name="form2" action="" onSubmit="update()">
<table>
<?php
$r=mysqli_fetch_array($q);
echo"<tr><td><input type='text' name='scatola' value='$r[0]'></td>
<td id='faldone'>$r[1]></td>
<td><input type='text' name='fascicolo' value='$r[2]'></td>
<td><input type='text' name='descrizione' value='$r[3]'></td>
<td><input type='text' name='tipodocumento' value='$r[4]'></td>
<td><input type='text' name='annicon' value='$r[5]'></td>
<td><input type='text' name='dal' value='$r[6]'></td>
<td><input type='text' name='al' value='$r[7]'></td>
<td><input type='text' name='estremidal' value='$r[8]'></td>
<td><input type='text' name='estremial' value='$r[9]'></td>
<td><input type='text' name='vecchiasegn' value='$r[10]'></td></tr>
</table>";
<input type="reset" value="reset"><input type="submit" value="conferma">
</form>
Upvotes: 0
Views: 86
Reputation: 6282
You can achieve all you want by simply using the GET
method and passing the value of faldone using a hidden
input field.
<form name="form2" action="" method="GET">
<table>
<?php
$r=mysqli_fetch_array($q);
echo"
<!-- use a hidden field to send the value of faldone -->
<input type='hidden' name='faldone' value='$r[1]'>
<tr><td><input type='text' name='scatola' value='$r[0]'></td>
<td id='faldone'>$r[1]></td>
<td><input type='text' name='fascicolo' value='$r[2]'></td>
<td><input type='text' name='descrizione' value='$r[3]'></td>
<td><input type='text' name='tipodocumento' value='$r[4]'></td>
<td><input type='text' name='annicon' value='$r[5]'></td>
<td><input type='text' name='dal' value='$r[6]'></td>
<td><input type='text' name='al' value='$r[7]'></td>
<td><input type='text' name='estremidal' value='$r[8]'></td>
<td><input type='text' name='estremial' value='$r[9]'></td>
<td><input type='text' name='vecchiasegn' value='$r[10]'></td></tr>
</table>";
<input type="reset" value="reset"><input type="submit" value="conferma">
</form>
Upvotes: 1
Reputation: 1586
Your code works fine but you have a few typo errors. The line
var al="document.form2.al.value;
has an extra " character as do the subsequent lines.
I have removed these and created a fiddle and it appears to work fine. It shows an alert box with the url of the post(get) and the element faldone
is included with the correct data.
Here is a fiddle of the code.
Upvotes: 0