需要帮助传递值以发布表格

时间:2018-06-29 18:42:52

标签: javascript

我正在尝试根据所选的单选按钮更改表格中的值。它会将密钥传递给php,而不是值传递给我的php。我正在尝试通过POST发送它,并在另一侧捡起变量

我正在研究以下示例:https://bootsnipp.com/snippets/featured/sexy-radio-butons

<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.1.0/js/bootstrap.min.js"></script>
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<style>
input[type=submit] {
    width: 5em;  height: 2em;
    font-size: 20px;
    font-weight: bold;
}
#radioBtn .notActive{
    color: #3276b1;
    background-color: #fff;
}
</style>
</head>
<body>
<br><br>
<h2>Notification settings for: ****@vtext.com</h2>
<br>
<br>
<form action="http://****.com/temp_update_notifications.php?v=1530296464" method="post">
  <input type="hidden" id="hash" name="hash" value="YgSeBiAcEg">
  <input type="hidden" id="email" name="email" value="****@vtext.com">
  <input class="btn btn-primary btn-lg" type="submit" value="Update">
  <br>
  <div class="container">
    <div class="row">
      <div class="form-group">
        <div class="col-sm-7 col-md-7">
          <div class="input-group">

              <b>Current setting: Active</b>
              <br>
              <div id="radioBtn" class="btn-group">
                <a class="btn btn-primary btn-sm active" data-toggle="3885 Walkin Door" data-title="-1">No Change</a>
                <a class="btn btn-primary btn-sm notActive" data-toggle="3885 Walkin Door" data-title="0">Active</a>
                <a class="btn btn-primary btn-sm notActive" data-toggle="3885 Walkin Door" data-title="1">1 Hour</a>
                <a class="btn btn-primary btn-sm notActive" data-toggle="3885 Walkin Door" data-title="3">3 Hours</a>
                <a class="btn btn-primary btn-sm notActive" data-toggle="3885 Walkin Door" data-title="8">8 Hours</a>
                <a class="btn btn-primary btn-sm notActive" data-toggle="3885 Walkin Door" data-title="12">12 Hours</a>
                <a class="btn btn-primary btn-sm notActive" data-toggle="3885 Walkin Door" data-title="24">24 Hours</a>
                <a class="btn btn-primary btn-sm notActive" data-toggle="3885 Walkin Door" data-title="168">7 days</a>
              </div>
              <input type="hidden" name="3885 Walkin Door" id="3885 Walkin Door">

          </div>
        </div>
      </div>
    </div>
   </div>
  </form>
<script>
$('#radioBtn a').on('click', function(){
    var sel = $(this).data('title');
   var tog = $(this).data('toggle');
  $('#'+tog).prop('value', sel);

    $('a[data-toggle="'+tog+'"]').not('[data-title="'+sel+'"]').removeClass('active').addClass('notActive');
    $('a[data-toggle="'+tog+'"][data-title="'+sel+'"]').removeClass('notActive').addClass('active');
})
</script>
</html>

1 个答案:

答案 0 :(得分:0)

在每个按钮标签上添加相同的“名称”和“值”标识符。

然后只需命名。

示例:

HTML:

<a class="btn btn-primary btn-sm active" name="WalkinDoor" value="-1">No Change</a>
<a class="btn btn-primary btn-sm notActive" name="WalkinDoor" value="0">Active</a>
<a class="btn btn-primary btn-sm notActive" name="WalkinDoor" value="1">1 Hour</a>


PHP:

$buttonValue = $_POST['WalkinDoor'];