动态更新php表单上的复选框

时间:2012-08-05 11:53:10

标签: php

这是我的项目,我必须选择该部分,然后根据该部分,如果它的“A”然后显示1 50的复选框,如果它的“B”则从51到100

这是我的主要代码:

<html>
<head>
<link rel="stylesheet" type="text/css" media="all" href="jsDatePick_ltr.min.css" />
<script type="text/javascript" src="jsDatePick.min.1.3.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
window.onload = function(){
    new JsDatePick({
        useMode:2,
        target:"inputField",
        dateFormat:"%d-%M-%Y"
    });
};
</script>
</head>
<?php
$dept =$_COOKIE[dept];
include_once("../Include/connectdb.php");
include_once("../Include/data_menu.php");
include_once '../Include/pagemaker.php';

?>
<script type="text/javascript">
$(document).ready(function()
{
$(".batch").change(function()
{
var id=$(this).val();
var dataString = 'year_join='+ id;

$.ajax
({
type: "POST",
url: "ajax_subject.php",
data: dataString,
cache: false,
success: function(html)
{
$(".subject").html(html);
} 
});

});
});
</script>





<script type="text/javascript">
$(document).ready(function()
{
    $(".section").change(function()
    {
        alert('asdfa');
        var id=$(this).val();
        var dataString = 'section='+ id;

        $.ajax
        ({
                type: "POST",
                url: "ajax_absent.php",
                data: dataString,
                cache: false,
                success: function(html)
                {
                    $(".absent").html(html);
                } 
        });

    });
});
</script>
</head>

<body>
<fieldset class="cbox"><legend>New Attendence System</legend>
<form name="frm" action=<?php print "edit_attendencePHP_NEW.php"; ?> method="GET"    
id="content">
<br><br>

<div style="margin:80px">
<label>Batch :</label> <select name="batch" class="batch">
<option selected="selected">--Select Batch--</option>
<?php
    $result = mysql_query("select distinct year_joining from student_profile  
order by year_joining ")or die(mysql_error());

while($year = mysql_fetch_assoc($result)){
if($year[year_joining]!="" && $year[year_joining]>"2008"){

  print "<OPTION value='$year[year_joining]'>$dept $year[year_joining]</OPTION>";
}  }
 ?>
</select>

<label>Section :</label> 
<select name="section" class="section">
        <OPTION value='A'> A</OPTION>
        <OPTION value='B'> B</OPTION>
</select>

  Date :<input type="text" size="12" id="inputField" name="date"/>

  <label>Hours :</label> <select name="hour" >
        <OPTION value='1'> 1</OPTION>
        <OPTION value='1'> 2</OPTION>
        <OPTION value='1'> 3</OPTION>

</select>
</br></br>
<label>Subject :</label> <select name="subject" class="subject">
<option selected="selected">------------Choose Subject------------</option>

  </select>
 </br>
    <label>Mark the Absenties : </label> 
    <input type="checkbox" class="section">
  <br/></br>
  <div class="absent"></div>

            <input class="bluebutton" type="submit" value="Go">    
</form><br>

<label class="comment">select a batch frm the list and press "Go"</label>
</fieldset>


</body>
</html>

这是我的ajax_absent.php,它可以单独运作..

<?php
include_once("../Include/connectdb.php");


if($_POST['section'])
{
$sec=$_POST['section'];
if($sec=="A")
    $j=1;
else if($sec=="B")
    $j=51;

    for($i=0;$i<=49;$i++)
        { $k=$j+$i;
        if($i%5==0)
        {   echo "</br>";       }   
            echo '<input type ="Checkbox" value="'.$i . '">'.$k .   
 '</option>';

        }



?>

我在同一个文件中为下拉菜单实现了相同的动态概念,但复选框只有一个复选框。

1 个答案:

答案 0 :(得分:1)

我发现了一些错误: -

您在jquery

中拥有以下代码的用户
$(".section").change(function()

中缺少部分类
<select name="section" >

替换

<select name="section" class="section">

您的代码中还有一个错误

您希望将输出存储在缺少的类中,并且您已在jquery中使用此代码

$(".absent").html(html); 

但您的HTML代码中不存在缺少的类请添加您的代码

<span class="absent"></span> 

<span class="absent"></span> 

试试这个

这是修改HTML代码

<html>
<head>
<link rel="stylesheet" type="text/css" media="all" href="jsDatePick_ltr.min.css" />
<script type="text/javascript" src="jsDatePick.min.1.3.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
window.onload = function(){
    new JsDatePick({
        useMode:2,
        target:"inputField",
        dateFormat:"%d-%M-%Y"
    });
};
</script>
</head>
<?php
$dept =$_COOKIE[dept];
include_once("../Include/connectdb.php");
include_once("../Include/data_menu.php");
include_once '../Include/pagemaker.php';

?>
<script type="text/javascript">
$(document).ready(function()
{
$(".batch").change(function()
{
var id=$(this).val();
var dataString = 'year_join='+ id;

$.ajax
({
type: "POST",
url: "ajax_subject.php",
data: dataString,
cache: false,
success: function(html)
{
$(".subject").html(html);
} 
});

});
});
</script>





<script type="text/javascript">
$(document).ready(function()
{
    $(".section").change(function()
    {
        alert('asdfa');
        var id=$(this).val();
        var dataString = 'section='+ id;

        $.ajax
        ({
                type: "POST",
                url: "ajax_absent.php",
                data: dataString,
                cache: false,
                success: function(html)
                {
                    $(".absent").html(html);
                } 
        });

    });
});
</script>
</head>

<body>
<fieldset class="cbox"><legend>New Attendence System</legend>
<form name="frm" action=<?php print "edit_attendencePHP_NEW.php"; ?> method="GET"    
id="content">
<br><br>

<div style="margin:80px">

<label>Section :</label> 
<select name="section" class="section">
        <OPTION value='A'> A</OPTION>
        <OPTION value='B'> B</OPTION>
</select>

  Date :<input type="text" size="12" id="inputField" name="date"/>

  <label>Hours :</label> <select name="hour" >
        <OPTION value='1'> 1</OPTION>
        <OPTION value='1'> 2</OPTION>
        <OPTION value='1'> 3</OPTION>

</select>
</br></br>
<label>Subject :</label> <select name="subject" class="subject">
<option selected="selected">------------Choose Subject------------</option>

  </select>
 </br>
    <label>Mark the Absenties : </label> 
    <input type="checkbox" class="section">
  <br/></br>
  <div class="absent"></div>

            <input class="bluebutton" type="submit" value="Go">    
</form><br>

<label class="comment">select a batch frm the list and press "Go"</label>
</fieldset>

输出enter image description here

if($_POST['section'])
{
$sec=$_POST['section'];
if($sec=="A")
    $j=1;
else if($sec=="B")
    $j=51;

    for($i=0;$i<=49;$i++)
        { $k=$j+$i;
        if($i%5==0)
        {   echo "</br>";       }   
            echo '<input type ="Checkbox" value="'.$i . '">';   


        }