my textboxes have same name and id with array
i am alerting the text box value onblur.It shows only the first text box value
I want to alert for every text box if value is not a number
Expand|Select|Wrap|Line Numbers
- <?php
- session_start();
- if (!$_SESSION['uname']) header("Location:login.php"); ?>
- <html><head><title>Attendance sheet</title>
- <link rel="stylesheet" href="att_style.css" type="text/css" >
- <script type="text/javascript">
- function IsNumber(strAlert)
- {
- //alert(strAlert);
- var txtb = document.getElementById('in_time[]').value;
- //for (var i = 0; i < txtb.length; i++) {
- //var txtv = txtb[i].value;
- alert(txtb);
- //}
- }
- </script>
- </head>
- <body>
- <?php
- $cnn = mysql_connect("localhost","root","");
- mysql_select_db("time_sheet",$cnn);
- $dbdate = mysql_query("SELECT start_mon,end_mon FROM admin");
- $dd = mysql_fetch_array($dbdate);
- $curmon = getdate();
- $nextmonth = $curmon['mon'] + 1;
- $start = "2012" . "-" . $curmon['mon'] ."-". $dd['start_mon'];
- $end = "2012" . "-". $nextmonth ."-". $dd['end_mon'];
- $_SESSION['fromdate'] = $start;
- $_SESSION['todate'] = $end;
- $dateMonthYearArr = array();
- $fromDateTS = strtotime($start);
- $toDateTS = strtotime($end);
- for ($currentDateTS = $fromDateTS; $currentDateTS <= $toDateTS; $currentDateTS += (60 * 60 * 24)) {
- $currentDateStr = date("M d",$currentDateTS);
- $notmysql[] = $currentDateStr;
- $currmysql = date("Y-m-d",$currentDateTS);
- $mysqlfor[] = $currmysql;
- }
- echo " No of days: " . count($mysqlfor);
- //Table for view
- if (isset($_REQUEST['sub'])) {
- $inti = $_POST['in_time'];
- $outi = $_POST['out_time'];
- $intime = serialize($inti);
- $outtime = serialize($outi);
- $inser = unserialize($intime);
- $outser = unserialize($outtime);
- $dbdate = mysql_query("SELECT start_mon,end_mon FROM admin");
- $dd = mysql_fetch_array($dbdate);
- $curmon = getdate();
- $nextmonth = $curmon['mon'] + 1;
- $dateMonthYearArr = array();
- $fromDateTS = strtotime($start);
- $toDateTS = strtotime($end);
- for($b = 0; $b < count($mysqlfor); $b++) {
- $qry = mysql_query("SELECT * FROM timetable where date = '".$mysqlfor[$b]."' ");
- $ds = mysql_fetch_array($qry);
- if(!$qry) die(mysql_error());
- $check = mysql_num_rows($qry);
- // print_r($inser);
- if($check == 0) {
- if($inser[$b] == "") $inser[$b] = '00:00';
- if($outser[$b] == "") $outser[$b] = '00:00';
- $ins = mysql_query("INSERT INTO timetable VALUES ('', '".$_SESSION['uname']."',
- '".$mysqlfor[$b]."', '".$inser[$b]."', '".$outser[$b]."', '') ");
- }
- else {
- //print_r($mysqlfor[$b]);
- $upd = mysql_query("UPDATE `timetable` SET `in` = '".$inser[$b]."',
- `out` = '".$outser[$b]."' WHERE `date` = '".$mysqlfor[$b]."' ");
- if(!$upd) die(mysql_error());
- }
- }
- }
- ?>
- <form name="myForm" method="post" action="">
- <table border="1" cellspacing="0" cellpadding="2">
- <tr><th scope="row">DATE</th>
- <?php
- for ($s = 0; $s < 10; $s++) {
- ?>
- <td align="center"><?php print_r($notmysql[$s]); } ?></td></tr>
- <tr><th scope="row">IN</th> <?php
- for ($ss = 0; $ss < 10; $ss++) { ///////////////getting from DB
- $sele = mysql_query("SELECT * FROM timetable where date = '".$mysqlfor[$ss]."' ");
- $emp = mysql_num_rows($sele);
- ?>
- <td align="center"> <?php
- $numrows = mysql_num_rows($sele);
- if($numrows == 0) {
- ?>
- <input name="in_time[]" id="in_time[]" type="text" onBlur="IsNumber();" size="5">
- </td>
- <?php
- }
- else {
- while($row1 = mysql_fetch_array($sele)) {
- ?>
- <input name="in_time[]" id="in_time[]" type="text" onBlur="IsNumber();"
- value="<?php echo $row1['in']; ?>" size="5"></td>
- <?php }
- }
- }?>
- </tr>
- <tr><th scope="row">OUT</th> <?php
- for ($v = 0; $v < 10; $v++) {
- ?>
- <td align="center"> <?php
- $sel2 = mysql_query("SELECT * FROM timetable where date = '".$mysqlfor[$v]."'");
- $numrows = mysql_num_rows($sel2);
- if($numrows == 0) { ?>
- <input name="out_time[]" id="out_time[]" type="text" size="5"></td>
- <?php
- }
- else {
- while($row2 = mysql_fetch_array($sel2)) { ?>
- <input name="out_time[]" id="out_time[]" type="text" onBlur="IsNumber();"
- value="<?php echo $row2['out']; ?>" size="5"></td>
- <?php
- }
- }
- }?>
- </tr>
- <tr><th scope="row">Late</th><?php for ($s = 0; $s < 10; $s++) {
- ?>
- <td align="center"><input name="late_time[]" id="late_time[]" onBlur="IsNumber();"
- type="text" size="5"></td>
- <?php
- }?>
- </tr>
- </table>
- <br><br>
- <!-- second tab-->
- <?php if(count($notmysql) >= 11) { ?>
- <table border="1" cellspacing="0" cellpadding="2"><tr><th scope="row">DATE</th>
- <?php
- for ($st = 10; $st < 20; $st++) { ?>
- <td align="center"><?php print_r($notmysql[$st]); ?></td>
- <?php
- }
- ?></tr>
- <tr><th scope="row">IN</th>
- <?php for ($g = 10; $g < 20; $g++) {
- $selec = mysql_query("SELECT * FROM timetable where date = '".$mysqlfor[$g]."'");
- $numrows = mysql_num_rows($selec);
- ?> <td align="center"> <?php
- if($numrows == 0) { ?>
- <input name="in_time[]" id="in_time[]" type="text" onBlur="IsNumber();" size="5"></td>
- <?php
- }
- else {
- while($secinrow = mysql_fetch_array($selec)) { ?>
- <input name="in_time[]" id="in_time[]" value="<?php echo $secinrow['in']; ?>" onBlur="IsNumber();"
- type="text" size="5"></td>
- <?php
- }
- }
- }?></tr>
- <tr><th scope="row">OUT</th>
- <?php for ($h = 10; $h < 20; $h++) {
- $select = mysql_query("SELECT * FROM timetable where date = '".$mysqlfor[$h]."'");
- ?>
- <td align="center"> <?php
- $numrows = mysql_num_rows($select);
- if($numrows == 0) {?>
- <input name="out_time[]" id="out_time[]" type="text" onBlur="IsNumber();" size="5"></td>
- <?php
- }
- else {
- while($secoutrow = mysql_fetch_array($select)) {
- ?>
- <input name="out_time[]" id="out_time[]" type="text" onBlur="IsNumber();"
- value="<?php echo $secoutrow['out']; ?>" size="5"></td>
- <?php }
- }
- }?></tr>
- <tr><th scope="row">Late</th>
- <?php for ($m = 10; $m < 20; $m++) { ?>
- <td align="center"><input name="late_time[]" id="out_time[]" onBlur="IsNumber();"
- type="text" size="5"></td> <?php
- }
- ?>
- </tr>
- </table>
- <?php } ?>
- <br/><br/>
- <!-- Third table-->
- <?php if(count($notmysql) >= 21) { ?>
- <table border="1" cellspacing="0" cellpadding="2">
- <tr>
- <th scope="row">DATE</th>
- <?php
- for ($tt = 20; $tt < count($notmysql); $tt++) {
- ?>
- <td align="center"><?php print_r($notmysql[$tt]); ?></td><?php }
- ?>
- </tr>
- <tr><th scope="row">IN</th>
- <?php for ($j = 20; $j < count($notmysql); $j++) {
- $selected = mysql_query("SELECT * FROM timetable where date = '".$mysqlfor[$j]."' ");
- ?> <td align="center"> <?php
- $numrows = mysql_num_rows($selected);
- if($numrows == 0) {?>
- <input name="in_time[]" id="in_time[]" type="text" onBlur="IsNumber();" size="5"></td>
- <?php }
- else {
- while($treinrow = mysql_fetch_array($selected)) {
- ?>
- <input name="in_time[]" id="in_time[]" type="text" onBlur="IsNumber();"
- value="<?php echo $treinrow['in']; ?>" size="5"></td>
- <?php
- }
- }
- }
- ?>
- </tr>
- <tr><th scope="row">OUT</th> <?php for ($k = 20; $k < count($notmysql); $k++) {
- $selectedr = mysql_query("SELECT * FROM timetable where date = '".$mysqlfor[$k]."'");
- $numrows = mysql_num_rows($selectedr);
- ?>
- <td align="center"> <?php
- if($numrows == 0) { ?>
- <input name="out_time[]" id="out_time[]" type="text" onBlur="IsNumber();" size="5"></td>
- <?php }
- else {
- while($treoutrow = mysql_fetch_array($selectedr)) {
- ?>
- <input name="out_time[]" id="out_time[]" onBlur="IsNumber();"
- value="<?php echo $treoutrow['out']; ?>" type="text" size="5"></td>
- <?php
- }
- }
- } ?>
- </tr>
- <tr><th scope="row">Late</th>
- <?php for ($s = 20; $s < count($notmysql); $s++) { ?>
- <td align="center">
- <input name="late_times[]" id="late_times[]" type="text" value="<?php ?>" size="5"></td> <?php
- } ?>
- </tr>
- </table>
- <?php } ?>
- <!--Table End -->
- <a style="float:right" href="logout.php">Logout</a>
- <p align="center"><input name="sub" type="submit" value="Save"></p>
- </form>
- </body>
- </html>