2013-07-31 34 views
0

我正在寻找一种解决方案在模态框中显示mysql结果。说我要制作投票表格。用户选择一个选项并点击提交。点击提交后,将调用一个模式框并显示他们刚刚选择的投票数量。如何在提交表单后在模态引导中显示mysql结果

我正在寻找这种有点例子,但没有结果。我想知道这个星球上是否有它们中的任何一个。所以你可以建议或给我一个想法如何实现这一点。

+0

这将是更多的JavaScript问题..你使用的是jQuery吗?如果没有,我会强烈推荐它。 –

+0

尼克,引导是基于jQuery的方式。 – Wilf

回答

0

如果您计算php中的投票数量,或者您可以使用您需要总票数的ID查询弹出窗口中的数据库,则可以在表单发帖后发送数据,因此在这种情况下,您将只需要传递id。

//This script reads the itema id and votes using class open-AddBookDialog and add the values //to input fields id and votes in modal box 
<script type="text/javascript"> 
    $(document).ready(function() { 
    $(".open-AddBookDialog").click(function() { 

     $('#id').val($(this).data('id')); 
     $('#votes').val($(this).data('votes')); 

     $('#myModal_3').modal('show'); 
    }); 
}); 
</script> 

// your button 
<input type="button" class="open-AddBookDialog" data-votes="<?php echo $votes;?>" data-id="<?php echo $id; ?>" role="button" data-toggle="modal" /> 

//Modal box 
<div id="myModal_3" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> 
    <div class="modal-body"> 
     <div class="clearfix"></div> 

      <form class="form-horizontal" method="post" action=""> 
     <div class="control-group"> 
      <label class="control-label" >Name</label> 
      <div class="controls"> 
      <input type="hidden" name="id" id="id" value=""/> 
      <input type="text" name="votes" id="votes" value=""/> </div> 
     </div> 

     <div class="control-group"> 
     <div class="controls"> 
      <input type="submit" class="btn btn-info" name="send" value="Send"> 
     </div> 
     </div> 


     </form> 
      <div class="clearfix"></div> 
     </div> 
    </div> 
    </div> 
+0

Cartina,谢谢你的代码。但这不完全是我要找的。我只是想要一个表单,在点击提交按钮后将值传递给模态。 – Wilf

+0

@wilf这个例子是为了演示我们如何将价值从形式传递给模态。页面顶部的脚本使用类从按钮中选择值并将其设置为模态中的隐藏字段。 – cartina

相关问题