gpt4 book ai didi

php - 如何使用javascript更改隐藏类型输入字段的值

转载 作者:行者123 更新时间:2023-11-28 16:21:21 25 4
gpt4 key购买 nike

我想要做的是每次用户单击“添加”按钮并调用 addRow 函数时,我还将调用 row_counter 函数来将隐藏输入类型字段的值设置为等于已创建的动态行数。因此,如果我动态创建了 3 行,则隐藏的输入类型字段必须为 3。我是 javascript 新手,所以请耐心等待。

<?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();

}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Inventory Area</title>

<link rel="stylesheet" href="../style/style.css" type="text/css" media="screen"/>

<SCRIPT language="javascript">
//Add Information
i=1;
function addRow(tableID,counter1) {
//The rows num starts from 0
var table = document.getElementById(tableID);

var rowCount = 7;
var row = table.insertRow(rowCount);

var cell1 = row.insertCell(0);

var cell2 = row.insertCell(1);
var element = document.createElement("input");
element.type = "text";
element.name = "information_" + i;
element.id = "information_" + i;
element.size = 84;
cell2.appendChild(element);
i++;
row_counter_inc(counter1);
}

function deleteRow(tableID) {
if(i>=2){
var table = document.getElementById(tableID);
table.deleteRow(i+5);
i--;
}
}
function row_counter_inc(counter2){
w=i;
w=w-1
document.getElementByID("counter2").value=w;
}

</SCRIPT>

<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>&nbsp;</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;

关于php - 如何使用javascript更改隐藏类型输入字段的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9503490/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com