Php 如何使用javascript更改隐藏类型输入字段的值
我想做的是,每次用户单击Add按钮并调用addRow函数时,我还将调用row_计数器函数,以将隐藏输入类型字段的值设置为已创建的动态行数。因此,如果我动态创建了3行,那么隐藏的输入类型字段必须是3。我是javascript新手,请耐心等待Php 如何使用javascript更改隐藏类型输入字段的值,php,javascript,html,Php,Javascript,Html,我想做的是,每次用户单击Add按钮并调用addRow函数时,我还将调用row_计数器函数,以将隐藏输入类型字段的值设置为已创建的动态行数。因此,如果我动态创建了3行,那么隐藏的输入类型字段必须是3。我是javascript新手,请耐心等待 <?php // Parse the form data and add inventory item to the system if (isset($_POST['product_name'])) { $product_name = my
<?php
// Parse the form data and add inventory item to the system
if (isset($_POST['product_name'])) {
$product_name = mysql_real_escape_string($_POST['product_name']);
$price = mysql_real_escape_string($_POST['counter']);
$details = mysql_real_escape_string($_POST['details']);
$category = mysql_real_escape_string($_POST['category_choice']);
$condition= mysql_real_escape_string($_POST['condition']);;
$supplier_choice= mysql_real_escape_string($_POST['supplier_choice']);;
// See if that product name is an identical match to another product in the system
$sql = mysql_query("SELECT id FROM products WHERE product_name='$product_name' LIMIT 1");
$productMatch = mysql_num_rows($sql); // count the output amount
if ($productMatch > 0) {
echo 'Sorry you tried to place a duplicate "Product Name" into the system, <a href="inventory_list.php">click here</a>';
exit();
}
// Add this product into the database now
$sql = mysql_query("INSERT INTO products (product_name, price, details, category, active, supplier, date_added)
VALUES('$product_name','$price','$details','$category','$condition','$supplier_choice',now())") or die (mysql_error());
$pid = mysql_insert_id();
// Place image in the folder
$newname = "$pid.jpg";
move_uploaded_file( $_FILES['my_photo']['tmp_name'], "../inventory_images/$newname");
//ean den yperxan oi 2 epomenes grammes ean ekana refresh tha prospathouse na perasei to idio proion ksana!!
header("location: inventory_list.php");
exit();
}
这应该适合您:
document.getElementById("counter").value = 3;
这应该适合您:
document.getElementById("counter").value = 3;
我这样做了,并尝试将counter的值插入我的sql,但在表的字段区域中,我得到一个空字段,这是代码的其余部分。您可以使用inventory\u list.php中的var\u dump$\u POST结果更新您的原始问题吗?我这样做了,并尝试将counter的值插入我的sql,但在表i得到一个空字段这里是代码的其余部分。您可以使用inventory\u list.php中的var\u dump$\u POST结果更新原始问题吗?我对您的问题进行了回滚。请不要再删除它了。我对你的问题做了回滚。请不要再删除它。
<div align="center" id="mainWrapper">
<?php include_once("template_header.php");?>
<div id="pageContent">
<div align="left" style="margin-left:24px">
<h2>Inventory List</h2>
<?php echo $productList ?>
</div>
</div>
<div>
<form action="inventory_list.php" enctype="multipart/form-data" name="my_Form" id="my_Form" method="post">
<a name="add_New_Product_Form" id="add_New_Product_Form">
<h2>Add New Product Form</h2>
</a>
<table width="80%" border="0" cellspacing="0" cellpadding="6" id="dataTable">
<tr>
<td>Όνομα</td>
<td>
<label>
<input name="product_name" type="text" id="product_name" size="80" />
</label>
</td>
</tr>
<tr>
<td>Κατάσταση</td>
<td>
<label>
<input type="radio" name="condition" value="1"> Ενεργό</input>
<input type="radio" name="condition" value="0"> Ανενεργό</input>
</label>
</td>
</tr>
<tr>
<td>Τιμή</td>
<td>
<label>
<input name="price" type="text" id="price" size="20" />
</label>
</td>
</tr>
<tr>
<td>Προμηθευτές</td>
<td>
<?php echo $suppliers_list; ?>
</td>
</tr>
<tr>
<td>Κατηγορία</td>
<td>
<?php echo $category_list; ?>
</td>
</tr>
<tr>
<td>Περιγραφή</td>
<td>
<label>
<textarea name="details" id="details" cols="64" rows="5"></textarea>
</label>
</td>
</tr>
<tr>
<td>Τεχνικά Χαρακτηριστικά</td>
<td>
<input type="text" name="information_0" id="information_0" size="84"/>
</td>
</tr>
<tr>
<td></td>
<td>
<input type="hidden" name="counter" id="counter"/>
<INPUT type="button" value="Προσθήκη" onClick="addRow('dataTable','counter')"/>
<INPUT type="button" value="Αφαίρεση" onClick="deleteRow('dataTable')"/>
</td>
</tr>
<tr>
<td>Φωτογραφία</td>
<td>
<label>
<input type="file" name="my_photo" id="my_photo"/>
</label>
</td>
</tr>
<tr>
<td> </td>
<td>
<label>
<input type="submit" name="button" id="button" value="Αποθήκευση" />
</label>
</td>
</tr>
</table>
</form>
</div>
<br /><br />
<?php include_once("../template_footer.php");?>
</div>
enter code here
document.getElementById("counter").value = 3;