2013-04-29 68 views
1

我绝不是一个JavaScript程序员,所以这将是很好,如果有人可以帮助我与此。如果在下面的示例中有多个这些评分部分在同一页面上。Radiobutton的价值到MySQL没有提交

现在我需要将单击的单选按钮的值发送到我的数据库,而无需提交按钮,最好不用刷新。

<body> 
    <section class="rating"> 
     <input type="radio" class="radio twenty" name="progress" value="twenty" id="twenty" <?php if($num === 1) { echo 'checked'; } ?>> 
     <label for="twenty" class="label">1</label> 

     <input type="radio" class="radio fourty" name="progress" value="fourty" id="fourty" <?php if($num === 2) { echo 'checked'; } ?>> 
     <label for="fourty" class="label">2</label> 

     <input type="radio" class="radio sixty" name="progress" value="sixty" id="sixty" <?php if($num === 3) { echo 'checked'; } ?>> 
     <label for="sixty" class="label">3</label> 

     <input type="radio" class="radio eighty" name="progress" value="eighty" id="eighty"<?php if($num === 4) { echo 'checked'; } ?>> 
     <label for="eighty" class="label">4</label> 

     <input type="radio" class="radio onehundred" name="progress" value="onehundred" id="onehundred" <?php if($num === 5) { echo 'checked'; } ?>> 
     <label for="onehundred" class="label">5</label> 

     <div class="progress"> 
      <div class="progress-bar"></div> 
     </div> 
    </section> 
</body> 

我已经设置了检查单选按钮的检索,使其与到等级5的1对应,所以我目前使用TESTDATA显示1到5个等级。

我不一定需要所有的细节,对需要完成的步骤的概述已经非常有帮助。

回答

3

这应该这样做

DEMO

将jQuery添加到头后包括 而且我将班级更改为进度条的ID

$(function() { // when document has loaded 
    $(".radio").on("click",function() { // all radios with class="radio ..." 
    // ajax get or post someserver.php?value=twenty/fourty... 
    $.get("someserver.php", {value:this.value},function(data) { 
     // add the returned value to a container 
     $("#progress-bar").append("Updated "+ data); 
    }); 
    }); 
}); 
+0

我想说'做它改变',但后来意识到everythng然后发射 – EaterOfCode 2013-04-29 11:11:54

+0

所以如果有'...',这不会发送'example.com'或'null'到'someserver.php'吗? – Dom 2013-04-29 11:25:17

+0

是的,你要么不需要给其他项目的无线电广播,要么添加输入[type = radio]或输入[name = progress]给选择器 – mplungjan 2013-04-29 11:27:24

2

您可以使用它的AJAX。如果您正在使用Jquery,则可以使用点击处理程序,它可以检测您的元素点击并启动一个函数调用,该函数调用又可以调用AJAX函数与您的服务器端代码进行交互,并将值发送到数据库中。

+0

稍微详细些会对您有所帮助哈哈。我目前已经从lynda.com下载了javascript和ajax教程。我目前还没有知道哪些确切的步骤。 – 2013-04-29 11:09:37

2
  • 添加的onclick或平变化作用到输入发送AJAX请求具有适当参数
  • recive请求,验证数据
  • 插入/更新行