dongrao9436 2012-08-05 11:53
浏览 97
已采纳

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

THis is my project , i have to select the section , then acording to that , if its "A" then checkbox from 1 50 will be displayed , and if its "B" then from 51 to 100

this is my main code :

<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>

This is my ajax_absent.php which is working fine separately ..

<?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>';

        }



?>

the same dynamic concept i implemented for drop down menu .. in the same file , but the check box is coming with just one check box.

  • 写回答

1条回答 默认 最新

  • dth2331 2012-08-05 11:55
    关注

    I have found some error:-

    you have user below code in jquery

    $(".section").change(function()
    

    but section class missing in

    <select name="section" >
    

    replace

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

    one more bug in your code

    you want to store output in absent class and u have use this code in jquery

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

    but absent class not exist in your html code please add in your code

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

    or

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

    try this

    this is modify html code

    <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>
    

    out putenter 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 . '">';   
    
    
            }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能