在单击单选按钮时将值传递给隐藏的输入



我试图传递一个值,当一个单选按钮点击到一个隐藏的输入,但它不工作,我试图在不同的页面上传递一个值,而不使用输出变量只有一个单选按钮与一个已经设置的值,它正在传递它,但我不知道为什么相同的代码不工作在$输出值

当单选按钮被点击时,这一行应该传递一个价格。

<input type="radio" onclick="document.getElementById(checked_radio).value='.$row["o_price"].'" />

="

<input type="hidden" id="checked_radio" name="hidden_price" value="">

完整代码是

$limit = '20';
$page = 1;
if($_POST['page'] > 1)
{
$start = (($_POST['page'] - 1) * $limit);
$page = $_POST['page'];
}
else
{
$start = 0;
}
$query = "
SELECT * FROM game
";
if($_POST['query'] != '')
{
$query .= '
WHERE game_name LIKE "%'.str_replace(' ', '%', $_POST['query']).'%" 
';
}
$query .= 'ORDER BY id ASC ';
$filter_query = $query . 'LIMIT '.$start.', '.$limit.'';
$statement = $con->prepare($query);
$statement->execute();
$total_data = $statement->rowCount();
$statement = $con->prepare($filter_query);
$statement->execute();
$result = $statement->fetchAll();
$total_filter_data = $statement->rowCount();
$output = '
<label>اجمالي الالعاب المتوفرة: '.$total_data.' لعبة</label>
<br />
';
if($total_data > 0)
{
foreach($result as $row)
{
$output .= '
<div class="col-md-3">
<form method="post" action="index.php?action=add&id='.$row["id"].'">
<div class="game">
<img src="images/'.$row["image"].'" class="img-responsive center-block" width="192" height="192" alt="'.$row["game_name"].'">
<h5 class="p-3 mb-2 bg-primary text-white" style="padding: 9px 1px 1px 1px; height: 40px;">'.$row["game_name"].'</h5>
<h4 class="text-success">نوع المتجر: '.$row["store"].'</h4>

<div class="radio">
<label class="radio text-danger"><h5>
سعر الأوفلاين: '.$row["o_price"].' ج.م المتوفر: '.$row["o_quantity"].'
<input type="radio" onclick="document.getElementById(checked_radio).value='.$row["o_price"].'" />
</label>
</h5>
</div>
<h5 class="text-danger"> سعر البريماري: '.$row["p_price"].' ج.م المتوفر: '.$row["p_quantity"].'</h5>
<h5 class="text-danger"> سعر السكندري: '.$row["s_price"].' ج.م المتوفر: '.$row["s_quantity"].'</h5>
<h5 class="text-danger"> سعر الكامل: '.$row["f_price"].' ج.م المتوفر: '.$row["f_quantity"].'</h5>
<h5 class="text-info"> مساحة اللعبة: '.$row["g_size"].' جيجا</h5>
<input type="text" name="quantity" class="form-control" value="1">
<input type="hidden" name="hidden_name" value="'.$row["game_name"].'">
<input type="hidden" name="hidden_store" value="'.$row["store"].'">
<input type="hidden" id="checked_radio" name="hidden_price" value="">
<input type="submit" name="add" style="margin-top: 5px;" class="btn btn-success"
value="إضافة إلى القائمة">
</div>
</form>
</div>
';
}
}
else
{
$output .= '
<tr>
<td colspan="2" align="center">عذرا! لا يوجد بيانات لعرضها</td>
</tr>
';
}

checked_radio在访问Element时应该是字符串。由于在php中进行连接,因此需要转义'checked_radio'

<input type="radio" onclick="document.getElementById('checked_radio').value='.$row["o_price"].'" />

或你可以通过php设置单选值然后点击传递当前单选值,比如

<input type="radio" onclick="document.getElementById('checked_radio').value=this.value" value='.$row["o_price"].' />

最新更新