简体   繁体   English

在PHP表单上动态更新复选框

[英]Dynamic Update of checkbox on php form

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 这是我的项目,我必须选择该部分,然后根据该部分进行选择,如果显示为“ A”,则将显示1 50的复选框,如果显示为“ B”,则为51到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 .. 这是我的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>';

        }



?>

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. 我在同一文件中为下拉菜单实现了相同的动态概念,但是该复选框仅带有一个复选框。

I have found some error:- 我发现了一些错误:

you have user below code in jquery 你有用户下面的代码在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 您想将输出存储在不存在的类中,并且您已在jquery中使用此代码

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

but absent class not exist in your html code please add in your code 但您的html代码中不存在缺少的类,请在您的代码中添加

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

or 要么

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

try this 尝试这个

this is modify html code 这是修改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>

out put 淘汰 在此处输入图片说明

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 . '">';   


        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM