JavaScript - Time Validation For Text Box
time validation for text box
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 Code: <?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> Similar TutorialsHey all. I have a simple validation I need to do. I need to just make sure that a Checkbox is checked, and that a Text field has content. Sounds simple but I cannot find any thing that has a check and a text field. Here what I have. Can I modify this script to do this? A Checkbox MUST be checked and Text field MUST be filled out. This currently does the text field fine, but no Checkbox obviously. How can I add a checkbox validation to this? Thats it. Any help is appreciated. Code: <script type="text/javascript"> var textFields = ["digsig"]; function validateForm( ) { var oops = ""; // must initialize this! var form = document.sig; for ( var t = 0; t < textFields.length; ++t ) { var field = form[textFields[t]]; var value = field.value.replace(/^\s+/,"").replace(/\s+$/,""); // trim the input if ( value.length < 1 ) { oops += "You MUST enter your Digital Signature"; } } if ( oops != "" ) { alert("ERROR:" + oops); return false; } } } </script> Hello, I have an existing php contact form which incorporates php validation (required name with only characters, valid email address format, and minimum message length) and re-captcha. I would like to add some "real time" validation to the fields on my form (there are 3 fields - name, email and message) before the "Submit" button is pressed. For example when the user tabs from one text box to the next but hasn't filled in the required information. I am totally new to any type of java, but am I right in thinking I need either JavaScript, Ajax or JQuery to perform real-time validation? If so, which should I be looking into and are there any basic examples of form validation? I want to keep my pup validation as I'm aware that php is client-side but still needed as people can turn Java off in their web browsers. Any tips and pointers will be very much appreciated! Thankyou, Tom hi all, im looking for a script that does the following when the page loads "text1" is displayed. then on the next line 2 seconds later "text2" is displayed and test1 is still displayed. and i need this to go to 5 lines so the final project should look like --- text1 text2 text3 text4 text5 thanks Hi Guys, I am looking for a script to change text on a page based on the time of day. From 9am - 5pm weekdays I would like the page to display 'Open', and outside of that window to display 'Closed'. I am using HTML & PHP. Any help would be greatly appreciated. Thanks, Matt I am the webmaster for the amateur radio club I am a member of. One of the pages on our newly redesigned website is a swap shop, where people can list items for sale. To keep the page from becoming too bloated and cumbersome, I stated in the header that ads would only be listed for 30 days. I found a javascript on JavaScriptKit.com that has the features I am looking for, in that it makes something disappear after a set period of time. I need help modifying it now to make a <div> disappear from the website, instead of just an image. Here is the code, with all credits shown: Code: <script> <!-- /* "Whats new?" image script- By JavaScript Kit (www.javascriptkit.com) Over 200+ free scripts here! */ //set the below to the image you wish to use as the "new" image var imagetag='<img src="../../news.gif">' var today=new Date() function expireat(expiredate){ var expire=new Date(expiredate) if (today.getTime()<=expire.getTime()) document.write(imagetag) } //--> </script> Anyone have an idea where to go after I remove the var imagetag? I know this requires setting the <div> element's visibility to "hidden" after the period of time set by the javascript. I just am not sure how to go about doing it. My website is engineered to be simple, no CMS in place. This is in the event that someone who has little to no HTML coding experience has to take over my webmaster duties in the future. Hi, I'm trying to display a time clock in input text box. The time should display in Time utilization box after clicking on START BUTTON. I tried the below code and it is not starting the time. However, I tried the javascript individually and it worked. Any help? PHP Code: <script type="text/javascript"> var seconds = 0; var minutes = 0; var hours = 0; function zeroPad(time) { var numZeropad = time + ''; while(numZeropad.length < 2) { numZeropad = "0" + numZeropad; } return numZeropad; } function countSecs() { seconds++; if (seconds > 59) { minutes++; seconds = 0; } if (minutes > 59) { hours++ minutes = 0; } document.getElementById("time_utilization").innerHTML = zeroPad(hours) + ":" + zeroPad(minutes) + ":" + zeroPad(seconds); } function startTimer() { action = window.setInterval(countSecs,1000); } </script> </head> <body> <?php include("header.php"); ?> <div class="art-content-layout"> <div class="art-content-layout-row"> <div class="art-layout-cell art-content"> <div class="art-post"> <div class="art-post-body"> <div class="art-post-inner art-article"> <form name="tracker" method="post" action="processor.php" onsubmit="return formCheck(this);"> <ul> <li class="mainForm" id="fieldBox_8"> <label class="formFieldQuestion">Start Time *</label><input readonly class=mainForm type=text name=start_time id=start_time size='30' value=''> <input type="button" id="start1_time" style="width: 100px" Value="Start Time" onClick="startTimer()"></li> <li class="mainForm" id="fieldBox_12"> <label class="formFieldQuestion">Time Utilization</label><input class=mainForm type=text name="time_utilization" id="time_utilization" size='8' value='00:00:00' ></li> <br /> <br /> <li class="mainForm"> <input id="saveForm" class="mainForm" type="submit" value="Submit" style="width : 100px"/> </li> </form> I am getting "Unknown Runtime Error at line 43". However, code has below line at link 43: Code: document.getElementById("time_utilization").innerHTML = zeroPad(hours) + ":" + zeroPad(minutes) + ":" + zeroPad(seconds); Is it possible to SplitText this way? The SplitText function has a unique name for each task Split1 - Split1(this.value) Split2 - Split2(this.value) Split3 - Split3(this.value) Code: <script type="text/javascript"> function Split1 (info) { if (info == '') { return; } var tarr = info.split(","); document.getElementById('field1').value = tarr[0]; document.getElementById('field2').value = tarr[1]; } function Split2 (info) { if (info == '') { return; } var tarr = info.split(","); document.getElementById('field3').value = tarr[2]; document.getElementById('field4').value = tarr[3]; } function Split3 (info) { if (info == '') { return; } var tarr = info.split(","); document.getElementById('field5').value = tarr[4]; document.getElementById('field6').value = tarr[5]; } </script> Hey, I've got the following problem: I want to edit this code: <a name="fb_share" type="button_count" href="http://www.facebook.com/sharer.pp"><img src="http://blog.bastian.info/wp-content/uploads/2010/02/facebook-glossy-logo.jpg"></a><script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script> So that after they click the button that triggers the facebook share, 7 seconds after they click it, some text appear and the picture they click disappears. Cheers Hi, I'd like to use the jQuery validation plugin as seen on the following example: http://docs.jquery.com/Plugins/validation#Example But it doesn't work properly if I use inline/in-filed labels. Any help is appreciated! Rain Lover I have a phone number field on my form that needs validation, but I'm not sure how to code this. I have the following function to validate a first name is entered and last name. The phone number field must match a 7 digit or 10 digit(with area code)phone number. I want to be able to include paranthese and/or hyphens for the valid phone number. function checkForm1() { if (document.forms[0].firstname.value.length == 0) { alert("You must put in a first name"); return false; } else if (document.forms[0].lastname.value.length == 0) { alert("You must put in a last name"); return false; } Hello I am trying to do something similar to this post http://www.codingforums.com/showthread.php?t=168903 except I need it to be dependent on the hour and minute. Background: I am trying to create a schedule website, the schedule has say 20 items and I want it to display the current "active" event in the schedule, 1 previous event and 3 future events so a total of 5 items from the schedule. An event can range from 30 minutes to 2 hours long, so simply using the above code will not work. It needs to take the minutes into consideration as well. Let me know if you have additional questions. EDIT: 17-Mar-12 @ 12:37PM I would rather not use a bunch of if statements. (http://www.codingforums.com/showthread.php?t=250358) The schedule could change mid day so having to go through and edit a bunch of if statements would not be ideal I am Gururaj. I have written a form in HTML which contains username,lastname,email,password and submit. I have written a javascript to validate this form [validate(username,lastname,email,password)]. On submit this javascript function will be called and hence form get validated. I am passing all the arguements(username,lastname,email and password) to the javascript function.. Is it possible to make me a code such that it should call an individual function for each field in the form.for ex:if i have not entered username, last name in the form and attempt to submit, only username arguement should be passed to the function as it comes first in the form. In other sense i want to validate individual text field validation of my form. So can anybody help me.It will be very needful to me. Hello im using dhtmlx grid in this cells i have from time and to time (i.e ind==1 and ind==2) i need to validate time where to-time must be greater than from-time else it should alert an message,i have writeen a normal Regular expression for the time validation.as the time is i string format i.e[05:00],please can any one send me code for that. Code: var err_str=""; function validate_grid(value,id,ind) { if(ind==1 || ind==2) { var patt=/^([0][0-9]|[1][0-9]|[2][0-3])[:]{1}[0-5][0-9]$/; if(!patt.test(value)) { mygrid.setCellTextStyle(id,ind,"background-color:yellow;"); if(err_str!="") err_str+="\n"+(ind+1)+".Enter numbers and : only.."; else err_str=(ind+1)+".Enter numbers and : only"; return false; } else { mygrid.setCellTextStyle(id,ind,"background-color:white;"); return true; } } } Hi Code: var err_str=""; function validate_grid(value,id,ind) { $("#result").html(" ").show(); if(ind==1 || ind==2) { var patt=/^([0][0-9]|[1][0-9]|[2][0-3])[:]{1}[0-5][0-9]$/; if(!patt.test(value)) { mygrid.setCellTextStyle(id,ind,"background-color:yellow;"); if(err_str!="") err_str+="\n"+(ind+1)+".Enter numbers and : only.."; else err_str=(ind+1)+".Enter numbers and : only"; return false; } else { mygrid.setCellTextStyle(id,ind,"background-color:white;"); return true; } } } alert(err-str); here ind==1 is from_time and ind==2 is to_time,i need to validate time as to_time must be always greater than from-time,if condition fails an alert msg should populate.time format is[05:00]as it is in string format im unable to do the validation for it.(ex:from-time=08:00 to-time=07:59 condition fails) thank you. hi im using dhtml xgrid where i need to do validation for time ,(from-time and to-time i.e ind==1 and ind==2 ) to-time must be greater than from-time else i need to alert a message to-time must be greater than from-time. can any one send me the code for it time format is[05:00]. Code: var err_str=""; function validate_grid(value,id,ind) { $("#result").html(" ").show(); if(ind==1 || ind==2) { var patt=/^([0][0-9]|[1][0-9]|[2][0-3])[:]{1}[0-5][0-9]$/; if(!patt.test(value)) { mygrid.setCellTextStyle(id,ind,"background-color:yellow;"); if(err_str!="") err_str+="\n"+(ind+1)+".Enter numbers and : only.."; else err_str=(ind+1)+".Enter numbers and : only"; return false; } else { mygrid.setCellTextStyle(id,ind,"background-color:white;"); return true; } } } 1 down vote favorite I do have the countdown script (see link below) to display the time between current time and the date given in real-time. However, I want to achieve to display the time difference between a given start and end time. Right now, it calculates from the current server time to the end time. I want to be able to set up my own start time and end time. Here is what I have: http://jsfiddle.net/BgEtE/ thank you for help hi, can some one help me how to get the time and date difference? given two time and date with the following format like in textbox A: 2011-05-03 17:35:47.0 and textbox B: 2011-05-03 16:35:47.0 then the output would be: 0 days, 1 hour, 0 minutes, 0 seconds regards, verve I'm not really a Java writer, so I don't know how to do this myself, though I imagine it would be pretty simple. I am looking to add a script to a webpage that allows users to input a time manually, and have it converted to GMT/Zulu time and display the converted time. I have seen a lot of time zone conversion scripts online, but they all just convert whatever the current system time is to another time zone. I am looking for a script that allows users to convert a time and show the zulu time, for times other than the current time. The time zone the inputed local time would be in is +4:30 (Kabul). I don't really care about style or aestehtics, just a simple script I can insert into a web page to have a time input field. The converted output time can appear in another field, a popup bubble, etc, again style isn't really an issue. It's really just to help people in my job who need to know what the GMT/Zulu time was for certain local times after the fact. One would think it shouldn't be that hard to just subtract 4:30 in your head, but apparently it is. Sorry if just asking for code outright like this is frowned upon. |