473,394 Members | 1,671 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

time validation for text box.

1
valid time in 24 hours format with no seconds

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
  1.     <?php
  2.     session_start();
  3.     if (!$_SESSION['uname']) header("Location:login.php"); ?>
  4.     <html><head><title>Attendance sheet</title>
  5.     <link rel="stylesheet" href="att_style.css" type="text/css" >
  6.     <script type="text/javascript">
  7.  
  8.     function IsNumber(strAlert)
  9.     {
  10.  
  11.     //alert(strAlert);
  12.     var txtb = document.getElementById('in_time[]').value;
  13.     //for (var i = 0; i < txtb.length; i++) {
  14.     //var txtv = txtb[i].value;
  15.     alert(txtb);
  16.     //}
  17.     }
  18.  
  19.     </script>
  20.     </head>
  21.     <body>
  22.     <?php
  23.     $cnn = mysql_connect("localhost","root","");
  24.     mysql_select_db("time_sheet",$cnn);
  25.  
  26.     $dbdate = mysql_query("SELECT start_mon,end_mon FROM admin");
  27.     $dd = mysql_fetch_array($dbdate);
  28.  
  29.     $curmon = getdate();
  30.     $nextmonth = $curmon['mon'] + 1;
  31.     $start = "2012" . "-" . $curmon['mon'] ."-". $dd['start_mon'];
  32.     $end =  "2012" . "-". $nextmonth ."-". $dd['end_mon'];
  33.     $_SESSION['fromdate'] = $start;
  34.     $_SESSION['todate'] = $end;
  35.  
  36.     $dateMonthYearArr = array();
  37.     $fromDateTS = strtotime($start);
  38.     $toDateTS = strtotime($end);
  39.  
  40.     for ($currentDateTS = $fromDateTS; $currentDateTS <= $toDateTS; $currentDateTS += (60 * 60 * 24)) {
  41.     $currentDateStr = date("M d",$currentDateTS);
  42.     $notmysql[] = $currentDateStr;
  43.  
  44.     $currmysql = date("Y-m-d",$currentDateTS);
  45.     $mysqlfor[] = $currmysql;        
  46.     }
  47.     echo "    No of days: " . count($mysqlfor);
  48.     //Table for view
  49.  
  50.     if (isset($_REQUEST['sub'])) {
  51.     $inti = $_POST['in_time'];
  52.     $outi = $_POST['out_time'];
  53.  
  54.     $intime = serialize($inti);
  55.     $outtime = serialize($outi);
  56.  
  57.     $inser = unserialize($intime);
  58.     $outser = unserialize($outtime);
  59.     $dbdate = mysql_query("SELECT start_mon,end_mon FROM admin");
  60.     $dd = mysql_fetch_array($dbdate);
  61.     $curmon = getdate();
  62.     $nextmonth = $curmon['mon'] + 1;
  63.  
  64.     $dateMonthYearArr = array();
  65.     $fromDateTS = strtotime($start);
  66.     $toDateTS = strtotime($end);
  67.  
  68.     for($b = 0; $b < count($mysqlfor); $b++) {
  69.     $qry = mysql_query("SELECT * FROM timetable where date = '".$mysqlfor[$b]."' ");
  70.     $ds = mysql_fetch_array($qry);
  71.  
  72.     if(!$qry) die(mysql_error());
  73.     $check = mysql_num_rows($qry);
  74.     //                print_r($inser);
  75.     if($check == 0) {
  76.     if($inser[$b] == "") $inser[$b] = '00:00';
  77.  
  78.     if($outser[$b] == "") $outser[$b] = '00:00';
  79.  
  80.     $ins = mysql_query("INSERT INTO timetable VALUES ('', '".$_SESSION['uname']."', 
  81.     '".$mysqlfor[$b]."', '".$inser[$b]."', '".$outser[$b]."', '') ");
  82.     }
  83.     else {
  84.     //print_r($mysqlfor[$b]);
  85.     $upd = mysql_query("UPDATE `timetable` SET `in` = '".$inser[$b]."',
  86.      `out` = '".$outser[$b]."' WHERE `date` = '".$mysqlfor[$b]."' ");
  87.     if(!$upd) die(mysql_error());                    
  88.     }
  89.     }
  90.     }
  91.     ?>
  92.     <form name="myForm" method="post" action="">
  93.     <table border="1" cellspacing="0" cellpadding="2">
  94.     <tr><th scope="row">DATE</th>
  95.     <?php
  96.     for ($s = 0; $s < 10; $s++) {
  97.     ?>
  98.     <td align="center"><?php print_r($notmysql[$s]); } ?></td></tr>
  99.  
  100.     <tr><th scope="row">IN</th> <?php 
  101.     for ($ss = 0; $ss < 10; $ss++) { ///////////////getting from DB
  102.     $sele = mysql_query("SELECT * FROM timetable where date = '".$mysqlfor[$ss]."' ");
  103.     $emp = mysql_num_rows($sele);
  104.     ?>
  105.     <td align="center"> <?php
  106.     $numrows = mysql_num_rows($sele);
  107.     if($numrows == 0) { 
  108.     ?>
  109.     <input name="in_time[]" id="in_time[]" type="text" onBlur="IsNumber();" size="5">
  110.     </td>
  111.     <?php
  112.     }
  113.     else {
  114.     while($row1 = mysql_fetch_array($sele))  {        
  115.     ?>
  116.     <input name="in_time[]" id="in_time[]" type="text" onBlur="IsNumber();" 
  117.     value="<?php echo $row1['in']; ?>" size="5"></td>
  118.     <?php } 
  119.     }
  120.     }?>
  121.     </tr>
  122.  
  123.     <tr><th scope="row">OUT</th> <?php 
  124.     for ($v = 0; $v < 10; $v++) {
  125.     ?>
  126.     <td align="center"> <?php
  127.     $sel2 = mysql_query("SELECT * FROM timetable where date = '".$mysqlfor[$v]."'");
  128.     $numrows = mysql_num_rows($sel2);
  129.     if($numrows == 0) { ?>
  130.     <input name="out_time[]" id="out_time[]" type="text" size="5"></td> 
  131.     <?php 
  132.     }
  133.     else {
  134.     while($row2 = mysql_fetch_array($sel2)) { ?>
  135.     <input name="out_time[]" id="out_time[]" type="text" onBlur="IsNumber();" 
  136.     value="<?php echo $row2['out']; ?>" size="5"></td>
  137.     <?php
  138.     }
  139.     }
  140.     }?>
  141.     </tr>
  142.  
  143.     <tr><th scope="row">Late</th><?php for ($s = 0; $s < 10; $s++) { 
  144.     ?>
  145.     <td align="center"><input name="late_time[]" id="late_time[]" onBlur="IsNumber();" 
  146.     type="text" size="5"></td> 
  147.     <?php  
  148.     }?>
  149.     </tr>
  150.     </table>
  151.     <br><br>
  152.     <!-- second tab-->
  153.     <?php if(count($notmysql) >= 11) { ?>
  154.     <table border="1" cellspacing="0" cellpadding="2"><tr><th scope="row">DATE</th>
  155.     <?php
  156.     for ($st = 10; $st < 20; $st++) { ?>        
  157.     <td align="center"><?php print_r($notmysql[$st]); ?></td>
  158.     <?php    
  159.     }
  160.     ?></tr>
  161.  
  162.     <tr><th scope="row">IN</th> 
  163.     <?php for ($g = 10; $g < 20; $g++) { 
  164.     $selec = mysql_query("SELECT * FROM timetable where date = '".$mysqlfor[$g]."'");
  165.     $numrows = mysql_num_rows($selec);
  166.     ?> <td align="center"> <?php
  167.     if($numrows == 0) { ?>    
  168.     <input name="in_time[]" id="in_time[]" type="text" onBlur="IsNumber();" size="5"></td>
  169.     <?php
  170.     }
  171.     else {
  172.     while($secinrow = mysql_fetch_array($selec)) { ?>
  173.     <input name="in_time[]" id="in_time[]" value="<?php echo $secinrow['in']; ?>" onBlur="IsNumber();"
  174.     type="text" size="5"></td>
  175.     <?php  
  176.     }
  177.     }
  178.     }?></tr>
  179.  
  180.     <tr><th scope="row">OUT</th>
  181.     <?php for ($h = 10; $h < 20; $h++) { 
  182.     $select = mysql_query("SELECT * FROM timetable where date = '".$mysqlfor[$h]."'");
  183.     ?>
  184.     <td align="center"> <?php
  185.     $numrows = mysql_num_rows($select); 
  186.     if($numrows == 0) {?>
  187.     <input name="out_time[]" id="out_time[]" type="text" onBlur="IsNumber();" size="5"></td>
  188.     <?php 
  189.     }
  190.     else { 
  191.     while($secoutrow = mysql_fetch_array($select)) {
  192.     ?> 
  193.     <input name="out_time[]" id="out_time[]" type="text" onBlur="IsNumber();" 
  194.     value="<?php echo $secoutrow['out']; ?>" size="5"></td>
  195.     <?php } 
  196.     }
  197.     }?></tr>
  198.  
  199.     <tr><th scope="row">Late</th>
  200.     <?php for ($m = 10; $m < 20; $m++) { ?>
  201.     <td align="center"><input name="late_time[]" id="out_time[]" onBlur="IsNumber();"
  202.     type="text" size="5"></td> <?php 
  203.     } 
  204.     ?>
  205.     </tr>
  206.     </table>
  207.     <?php } ?> 
  208.     <br/><br/>
  209.  
  210.     <!-- Third table-->
  211.     <?php if(count($notmysql) >= 21) { ?>
  212.     <table border="1" cellspacing="0" cellpadding="2">
  213.     <tr>
  214.     <th scope="row">DATE</th>
  215.     <?php
  216.     for ($tt = 20; $tt < count($notmysql); $tt++) {     
  217.     ?>
  218.     <td align="center"><?php print_r($notmysql[$tt]); ?></td><?php } 
  219.     ?>
  220.     </tr>
  221.  
  222.     <tr><th scope="row">IN</th>
  223.     <?php for ($j = 20; $j < count($notmysql); $j++) {
  224.     $selected = mysql_query("SELECT * FROM timetable where date = '".$mysqlfor[$j]."' ");
  225.     ?> <td align="center"> <?php
  226.     $numrows = mysql_num_rows($selected);
  227.     if($numrows == 0) {?>
  228.     <input name="in_time[]" id="in_time[]" type="text" onBlur="IsNumber();" size="5"></td>
  229.     <?php }
  230.     else {
  231.     while($treinrow = mysql_fetch_array($selected)) {
  232.     ?>
  233.     <input name="in_time[]" id="in_time[]" type="text" onBlur="IsNumber();"
  234.     value="<?php echo $treinrow['in']; ?>" size="5"></td> 
  235.     <?php
  236.     }
  237.     }
  238.     }
  239.     ?>
  240.     </tr>
  241.  
  242.     <tr><th scope="row">OUT</th> <?php for ($k = 20; $k < count($notmysql); $k++) { 
  243.     $selectedr = mysql_query("SELECT * FROM timetable where date = '".$mysqlfor[$k]."'");
  244.     $numrows = mysql_num_rows($selectedr);
  245.     ?>
  246.     <td align="center"> <?php    
  247.     if($numrows == 0) { ?>    
  248.     <input name="out_time[]" id="out_time[]" type="text" onBlur="IsNumber();" size="5"></td> 
  249.     <?php }
  250.     else {
  251.     while($treoutrow = mysql_fetch_array($selectedr)) {
  252.     ?>    
  253.     <input name="out_time[]" id="out_time[]" onBlur="IsNumber();" 
  254.     value="<?php echo $treoutrow['out']; ?>" type="text" size="5"></td> 
  255.     <?php 
  256.     }
  257.     }
  258.     } ?>
  259.     </tr>
  260.  
  261.     <tr><th scope="row">Late</th>
  262.     <?php for ($s = 20; $s < count($notmysql); $s++) { ?>
  263.     <td align="center">
  264.     <input name="late_times[]" id="late_times[]" type="text" value="<?php ?>" size="5"></td> <?php 
  265.     } ?>
  266.     </tr>
  267.     </table>
  268.     <?php } ?>
  269.     <!--Table End -->
  270.     <a style="float:right" href="logout.php">Logout</a>
  271.     <p align="center"><input name="sub" type="submit" value="Save"></p>
  272.     </form>
  273.     </body>
  274.     </html>
Mar 3 '12 #1
1 1956
Dormilich
8,658 Expert Mod 8TB
ids must be unique …
Mar 3 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Megha Vishwanath | last post by:
Hi, We have an application where my clients may be at different timezones. I need to validate time across the timezones with javascript. The date object in JavaScript does not allow me to get...
6
by: Kenneth | last post by:
Hello, I'm having some serious problems debugging a script that I'm trying to make work. I'm working on a form where a user can type in a time (in the format of HH:MM), and another script...
1
by: simina | last post by:
Hi... I have an "appointments" page where the user should (or not necessarily) choose a date and time for his appointment, from 6 combo boxes:year, month, day, hour, minute and AM or PM, without...
0
by: Al | last post by:
Hi, I'm using an asp:textbox in a form and I want to use the equivalent of the onkeyup event of a "normal" input text. So far, it seems that all validator performs a check up only on...
2
by: Chris | last post by:
Hi, I have a texbox in a webform that is supposed to hold Dates in a specific format : e.g. 20-12-2004 What is the best way to make sure that the entered data is in the correct format ? ...
0
by: R.A.M. | last post by:
Hi, Do you know if using asp: validators I can have validation text in browser popup message box? Thank you very much for your help. /RAM/
1
menayah
by: menayah | last post by:
Hi all, Can i use vb validators to validate a date (MM/DD/YY) from a text box ? and also time (HH:MM am/pm)? How to do this validation in a .net webform?
1
by: narend | last post by:
I want to validation in time in 24:00 Hours format.. i am using in txtbox in html
2
by: DrSporkeh | last post by:
Hai everyone, i need some help :o basically im trying to set some validation rules for an 'employees' table. firstly i've set it to you have to be 16 to work here under 'Date Of Birth' ...
7
by: dougancil | last post by:
I'm trying to use required validation controls on two text boxes and tried using the following code: <asp:TextBox ID="starttimeInput" runat="server" Width="130px" Height="23px"></asp:TextBox>...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.