-1

当单选按钮单击隐藏输入但它不起作用时,我试图传递一个值,我试图在不同的页面上传递一个值而不使用输出变量,只使用一个具有已设置值的单选按钮并且它正在传递它,但我不知道为什么相同的代码在 $output 值中不起作用。

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

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

到 value="" 内的这一行

<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>
  ';
}
4

1 回答 1

0

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"].' />
于 2021-09-08T01:55:55.143 回答