2012-12-17 26 views
0

我在一个php文件中有两种形式。 Form1将从用户处获得输入,并将查询传递给Mysql数据库并从数据库中检索数据,并且必须填充Form2。如何在Jquery按钮上单击加载表单?

最初隐藏Form2,当用户在Form1中选择输入并单击提交时,表单值将通过表单POST传递给php部分,并执行mysql提取并显示带有值的Form2。 Form1的

输入按钮:

<input id="buttonProductionSummary" class="buttonProductionSummary" type="submit" value="Submit" /> 

代码以POST形式值:

$date=$_POST['datepicker']; 
$machine = $_POST['selectMachine']; 
$user = $_POST['selectUser']; 
$shift=$_POST['selectShift']; 
$start_time_query = mysql_query("select time from rpt_shift_log where ((date='$date' and shift_def='$shift' and event_type='$even_type_up_id') and (machine='$machine' and employee='$user'))"); 


while($start_time_Row = mysql_fetch_assoc($start_time_query)) 
{ 
    $start_time = $start_time_Row['time'];  
} 

和我使用在这样窗体2的文本框中的计算值。

<input id="start_time_text" class="start_time_text" type="text" name="start_time_text" value="<?php echo $start_time?>"> 

但现在我已经阻止脚本加载按钮单击Form2。 jQuery代码加载在按钮单击窗体:

<script type="text/javascript"> 
    $(document).ready(function(){ 

     $("#buttonProductionSummary").click(function(e) { 

      $("#productionForm").show(); 

      e.preventDefault(); 
     }); 
    }); 
</script> 

的问题是,如果jQuery脚本执行,表单POST不会发生。如果POST发生,我必须评论脚本。

我该如何执行POST,并从数据库中检索数据,然后用检索到的数据显示Form2。

有人可以帮我吗?

回答

1

你知道e.preventDefault();是做什么的吗?它会停止发射的默认操作!所以表单不会提交。如果您不想回发该页面,则需要向服务器提供Ajax call以获取第二个表单的数据。

$("#buttonProductionSummary").click(function(e) { 
     $.post("test.php", $("#testform").serialize(), function(data) { 
      //do something with the data returned from the server. 
      $("#productionForm").show(); 
     }); 
     e.preventDefault(); 
    }); 
+0

我在窗体的同一页中发布值。我简短地修改了我的问题。 – Allen