Query in javascript

Hi All,
Im new to javascript and there is a requirement to do a date validation. I need to validate the date entered in a textbox which is in a format DDMMYYYY. please can you provide me the javascript code for this?
thanks,
mehul j

/* **** DATE VALIDATION ****/
function validate(obj,max){
if(obj.value!=""){
if (isDate(obj)==false){
return false
return true
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;
function isInteger(s){
var i;
for (i = 0; i < s.length; i++){  
// Check that current character is number.
var c = s.charAt(i);
if (((c < "0") || (c > "9"))) return false;
return true;
function stripCharsInBag(s, bag){
var i;
var returnString = "";
// Search through string's characters one by one.
// If character is not in bag, append to returnString.
for (i = 0; i < s.length; i++){  
var c = s.charAt(i);
if (bag.indexOf(c) == -1) returnString += c;
return returnString;
function daysInFebruary (year){
// February has 29 days in any year evenly divisible by four,
// EXCEPT for centurial years which are not also divisible by 400.
return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
function DaysArray(n) {
for (var i = 1; i <= n; i++) {
this[i] = 31
if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
if (i==2) {this[i] = 29}
return this
function isDate(obj){
var dtStr=obj.value;
var daysInMonth = DaysArray(12)
var pos1=dtStr.indexOf(dtCh)
var pos2=dtStr.indexOf(dtCh,pos1+1)
var strDay=dtStr.substring(0,pos1)
var strMonth=dtStr.substring(pos1+1,pos2)
var strYear=dtStr.substring(pos2+1)
strYr=strYear
if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
for (var i = 1; i <= 3; i++) {
if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
month=parseInt(strMonth)
day=parseInt(strDay)
year=parseInt(strYr)
if (pos1==-1 || pos2==-1 ){
alert("The date format should be : DD/MM/YYYY")
obj.focus();
obj.select();
return false
if (strMonth.length<1|| month<1 || month>12){
alert("Please enter a valid month")
obj.select();
obj.focus();
return false
if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
alert("Please enter a valid day")
obj.select();
obj.focus();
return false
if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
obj.select();
obj.focus();
return false
if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
alert("Please enter a valid date")
obj.select();
obj.focus();
return false
return true
}

Similar Messages

  • How to execute a query in javascript

    i have to give alert("record exists"),if the record alredy exists in the database.how to do it, by executing a query in javascript. please suggest me something with example

    You cant use Javascript itself for queries
    The query will be done in your java code .
    Easiest soloution is to simply submityour page and have it display the exist warning as response.
    More complex answer is to use XMlHttprequest to do the query in the background and have it eventually display the warning

  • Database connection(select ,insert query) within javascript function

    Hi ,
    How to write the database connection(insert,delete or select query) within javascript function.Is it possible.Anyone can you help me
    than you

    Hi ,
    How to write the database connection(insert,delete
    ete or select query) within javascript function.Is it
    possible.No

  • Fetching file size using CAML query in Javascript client object model

    Hi,
    I am using the Javascript client object model to retrieve contents of a document library.
    I have a document library, which contains a folder "Folder1" . "Folder1" has a zip file. I would like to get the file size of the zip file.
    I have tried the below code, but not sure, how to fetch the file size.
    function FetchImage() {
    var clientcontext = new SP.ClientContext.get_current();
    var oweb = clientcontext.get_web();
    var olibrary = oweb.get_lists().getByTitle(DocLibrary);
    var query = new SP.CamlQuery();
    query.set_folderServerRelativeUrl("Lists/DocLibrary/folder1/");
    folder = olibrary.getItems(query);
    clientcontext.load(folder, 'Include(Title,ContentType, FileLeafRef,FileDirRef,File)');
    clientcontext.executeQueryAsync(Function.createDelegate(this, this.RenderDataOnSuccess), Function.createDelegate(this, this.RenderDataOnFailure));
    function RenderDataOnSuccess() {
    var ListEnumerator = this.folder.getEnumerator();
    while (ListEnumerator.moveNext()) {
    var currentItem = ListEnumerator.get_current();
    if (_contentType.get_name() != "Folder") {
    var File = currentItem.get_file();
    if (File != null) {
    // Fetch file size
    How to fetch the file size?
    Thanks

    <script>
    function getSize()
            var myFSO = new ActiveXObject("Scripting.FileSystemObject");
            var filepath = document.upload.file.value;
            var thefile = myFSO.getFile(filepath);
            var size = thefile.size;
            alert(size + " bytes");
    </script>
    http://social.msdn.microsoft.com/Forums/en-US/e5d2ff3d-01c7-4cc0-a081-29a4dfbb0fad/getting-the-sharepoint-list-attachment-size-using-javascript?forum=sharepointcustomizationlegacy

  • SQL Query in Javascript

    Hi All,
    I have an SQL query which needs to be invoked when ever javscript function is called.
    Is it possible in Oracle Apex to embed a SQL query in the javascript function...If so, Please can anyone provide me with a right syntax ???
    Regards,
    Sandeep Reddy

    Thank you so much for your reply..
    I tried implementing it but facing the problem in PL/SQL code defined in the application process.. I am getting the coloum name is invalid..however, the coloum is valid for the table.
    declare
    lineprice LINEITEM%rowtype;
    Begin
    select LineUnitPrice
    into lineprice
    from LINEITEM
    where PriceCategoryID = :PRICECATEGORY AND LineItemID = :LINEITEM;
    htp.prn(lineprice);
    exception when others then htp.prn('An error occurred retrieving record');
    end;
    sqlerrm:ORA-06550: line 7, column 45:PL/SQL: ORA-00904: "LINEITEMID": invalid identifierORA-06550: line 4, column 1:PL/SQL: SQL Statement ignoredORA-06550: line 8, column 1:PLS-00306: wrong number or types of arguments in call to 'PRN'ORA-06550: line 8, column 1:PL/SQL: Statement ignored
    Please let me the know the correct path to sort out this problem..

  • PostGre SQL Query In JavaScript

    Is it possible to run the query in the javascript.
    I wil b passing an id from the jstl to a method which is implemented in javascript .using that id can i access the values from the database?
    plz send me some dummy code if possible
    Thanks ..

    There's a very simply difference between PHP and JavaScript:
    PHP runs on the Server.
    JavaScript runs on the Client. (*)
    That's a pretty big difference.
    (*) Strictly speaking both could theoretically run both on the Server and Client, but that's the common setting.

  • Problem with caml query in javascript

    hi friends
    i am using caml query to retrieve single list item
    ReviewQuery.set_viewXml('<view><query><Where><Eq><FieldRef Name=\'PNet_x002d_No\' /><Value Type=\'Text\'>'+id123+'</Value></Eq></Where></query></view>');
    my problem is if quried id is available in list it is showing properly. but if queried item is not there then it is showing other item in it.

    Hi,
    I suggest you debug the code and check if the variable value is valid.
    Here is a code snippet for your reference :
    <script src="http://code.jquery.com/jquery-1.10.2.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    _spBodyOnLoadFunctionNames.push("callCSOM");
    function callCSOM()
    $("#Button1").click(function()
    // Make sure the SharePoint script file 'sp.js' is loaded before your code runs.
    ExecuteOrDelayUntilScriptLoaded(sharePointReady, "sp.js");
    function sharePointReady()
    getListItems();
    var clientContext;
    var currentUser;
    var targetWeb;
    var message = "Web retrieved:";
    function getListItems()
    // Create an instance of the current context to return context information
    clientContext = SP.ClientContext.get_current();
    //Returns the list with the specified title from the collection
    var oList = clientContext.get_web().get_lists().getByTitle('list');
    var camlQuery = new SP.CamlQuery();
    camlQuery.set_viewXml(‘<ViewFields><FieldRef Name='Title' /></ViewFields><Where> <Eq><FieldRef Name='Title' /><Value Type='Text'>12</Value></Eq> </Where>');
    this.collListItem = oList.getItems(camlQuery);
    clientContext.load(collListItem);
    clientContext.executeQueryAsync(onRequestSucceeded, onRequestFailed);
    function onRequestSucceeded()
    var listItemEnumerator = collListItem.getEnumerator();
    while (listItemEnumerator.moveNext())
    //Gets the current element in the collection
    var oListItem = listItemEnumerator.get_current();
    message += '___'+'Title: ' + oListItem.get_item('Title');
    message += '___'+'ID: ' + oListItem.get_item('ID');
    message += '________________________________________________';
    $("#div1").text(message);
    //the delegate of the method that is called when the request is executed unsuccessfully
    function onRequestFailed(sender, args)
    alert('Error: ' + args.get_message());
    </script>
    <input id="Button1" type="button" value="Run Code"/>
    <p/>
    <div id="div1">test</div>
    Also, you can build CAML Query in the CAML Designer:
    http://www.camldesigner.com/
    Feel free to reply if the issue still exists.
    Best regards
    Patrick Liang
    TechNet Community Support

  • CF query and Javascript

    hi Guys,
    Im trying to creat a dynamic javascript list, populating it
    using a CF query.
    Can anyone tell me how I can loop through the query and set
    the options of the list?
    Here is my code but it doesnt work.
    Please help
    Thankyou
    <CFquery name="avequipment" datasource="itsupport"
    username="#dsn_username#" password="#dsn_password#">
    SELECT Equipment FROM JL_av_items ORDER BY Equipment
    </cfquery>
    //add options to equipment select list
    var recordcount =
    '<cfoutput>#avequipment.recordcount#</cfoutput>';
    for(t=1; t<=recordcount; t++)
    theOption=document.createElement('option');
    theText=document.createTextNode('<cfoutput>#equipment#</cfoutput>');
    theOption.appendChild(theText);
    theOption.setAttribute("value",'<cfoutput>#abbreviation#</cfoutput>');
    itemselect.appendChild(theOption);

    Thnaks for all your replies.
    Dan - I only have version 6.1 so I guess your way wouldnt
    work.
    Ive found a way to do this, but Its still not perfect.
    I create the valuelists in CF and then put them to a JS list.
    I then use the split function to assign each key to an an array,
    then I loop through the array.
    Problem is, can anyone tell me how I can get rid of any white
    space when I creat the value list?
    Its causing meproblems.
    Thankyou
    <CFquery name="avequipment" datasource="itsupport"
    username="#dsn_username#" password="#dsn_password#">
    SELECT equipment, abbreviation FROM JL_av_items
    </cfquery>
    <!--- create lists --->
    <cfset title = #ValueList(avequipment.Equipment)#>
    <cfset abb = ValueList(avequipment.abbreviation)>
    <script>
    // set variables/ lists in JS
    var recordcount =
    '<cfoutput>#avequipment.recordcount#</cfoutput>';
    var itemstring = '<cfoutput>#title#</cfoutput>';
    var abbstring = '<cfoutput>#abb#</cfoutput>';
    //split strings
    var items = itemstring.split(" ,");
    var abbs = abbstring.split(" ,");
    for (var y = 0; y < recordcount; y++)
    document.write(y + items[y] + abbs[y] + "<br>");
    </script>

  • Query regarding Javascript in Visual Web JSF

    Hi,
    I am learning to use Visual web JSF using IDE Netbeans 6.5. I have a doubt regarding using Javascript in the .jsp file. Whenever I use document.getElementById("component-ID").value, I got an error as "component-ID has no properties". It returns null.
    Can any one tell me how to handle getElementId()? Or there are any other way to handle javascript in visual web JSF?
    Thanks.

    Thanks for the quick reply. I have seen the generated HTML. The component say 'txtPId' is referred as '_form1:txtPId'. So I have tried the following code:
        function setFocusOnFirst() {      
                       var xyz = document.getElementById('_form1:txtPId');
                       xyz.focus();
       <webuijsf:button binding="#{Page3.btnClick}" id="btnClick" style="height: 48px; left: 719px; top: 192px; position: absolute; width: 192px"   text="Click" onClick="setFocusOnFirst()"/>But it's not working. Should I do it in this way? Please guide.
    Thanks.

  • CAML Query with Javascript value

    Hey everyone,
    I am building an Sharepoint 2013 app (SharePoint-Hosted) and using a CAML Query to get the current Item.
    The Current Item ID is 1 and i stored it in AccountID, but i want that variable inserted in the CAML Query so i get the proper information.
    var AccountID = 1
    camlQuery.set_viewXml('<View><Query><Where><Eq><FieldRef Name=ID LookupId="TRUE"/><Value Type="Text">1</Value></Eq></Where></Query></View>');
    But instead of putting the '1' value in the CAML Query, i want the variable AccountID in it... but how?
    Already tried this, but that didn't work:
    camlQuery.set_viewXml('<View><Query><Where><Eq><FieldRef Name=ID LookupId="TRUE"/><Value Type="Text">' + AccountID + '</Value></Eq></Where></Query></View>');
    Can someone help me with this?
    In forward, many thanks!

    Right, you have to use single quotes in a string literal inside double quotes. Just making sure it didn't have NO quotes, as your initial post showed.
    Is the ID field actually a lookup field? Or is it just the built-in ID field of the list? If it isn't a field of TYPE Lookup, try this:
    camlQuery.set_viewXml("<View><Query><Where><Eq><FieldRef Name='ID' /><Value Type='Number'>" + AccountID + "</Value></Eq></Where></Query></View>");
    Danny Jessee
    MCPD - SharePoint Developer 2010
    MCTS - SharePoint 2010, Configuring
    dannyjessee.com/blog

  • Query Parameter Data Type error betwee IE6 and IE7

    Hello all.
    This is a strange one. Using MII v12. When setting parameters for a SQL query from Javascript, the query executes properly on IE7 but generates errors on IE6. The errors are JDBC errors having to do with "Conversion failed when converting datetime from character string." and "Error converting data type varchar to numeric." I don't get any browser errors, only Java errors and NetWeaver log entries.
    What is the source of this data typing error?

    Hi, Sparks.
    Actually, IE was always an anomaly when it came to proper typing of objects in Javascript, so it let you get away with things that really shouldn't work.
    In general, you should use the Number Javascript type for number properties (e.g. setRowCount(), setXAxisMinRange(), etc) and strings for just about everything else.  If I recall, Javascript will handle most of the type conversions to a String property, but not necessarily to a Number property.
    You can use the parseInt() and parseFloat() methods to convert from strings to numbers in Javascript.
    In general, it's a good practice to be "type aware" in your Javascript code anyway, and this will ensure that it runs in other browsers and future browsers.
    Rick

  • JavaScript not working in safari on my iPhone eventhough kept on.not able to do online banking on my iPhone due to this problem

    Can anybody answer my query regarding JavaScript on iPhone in safari.

    I've also tried m4v and avi files. Is there another file format that will work?

  • Sending Query to query template

    Hi,
    is it possible to send query from Html page to query template. for example, i create query template as IDBC server and in fixed query mode without giving any query. just blank. in page generator i mapped with iCommand. Now i want to send query from javascript by using getQueryObject. how to send it?
    -senthil

    Senthil,
    As John indicated, using the built-in query parameter [Param.x] allows you to be very dynamic in your approach, but document.APPLET.getQueryObject().setQuery('SELECT....'); would be the same thing if you just wanted to pass in the whole fixed query statement.
    I may be getting ahead of things, but I can't help but think you are heading down a bad development path by burying all of your queries in the client side script.  You can use iCommand applets as recordset objects, but they will always be client sided, not server sided like ado recordsets in asp.  I've seen far too many system integrator botched applications where the the body onload was used to trigger javascript that attempts to force queries into applets when they have not been initialized by the JRE.  By nature Query Templates themselves can be filled with [Param.x]'s but trying to develop large amounts of application content where the select statements are assembled in client side javascript can lead to all sorts of supportability issues for the customer.  Imagine a customer going to training, and understanding the basics of query templates, and then trying to reverse engineer your page with one query template called "SQLGeneric" and all of the logic buried in javascript.  He/she opens the template and all they find is a FixedQuery with [Param.1] - can you envision their confusion?  Then they look at the 1000 - 2000 lines of javascript that I've seen at times?
    Can you provide the business case as to why you would not create a simpler query template minded approach, or would want to construct the queries this way?
    Regards,
    Jeremy

  • Report Row With Detail (AJAX) by Carl - How to implement?

    I just had a look at Carl's example place and I'd like to implement his Report Row With Detail feature. But how, it's made up of 3 sections:
    1. a query
    2. javascript
    3. application process
    The query on which the report is based and where I want this feature is:
    select leverancier, artnr, vendorcode from plijst where productgroep = :p1_assortiment_tree or subgroep = :p1_assortiment_tree
    A break is defined on Leverancier
    I understand the query and the application process part. But where goes the Java part???
    Peter
    Message was edited by:
    Pete

    Tried to upload your example application, unfortunately it does not seem to upload properly in my APEX v2.0 environment
    Can you please confirm if your example works with APEX version 2
    and does the Javascript go in the Page Header or Region Header/ Footer area
    thankyou
    Frank

  • How can I set an alarm clock set to a time zone?

    Hi,
    I am about to go traveling quite a bit in multiple time zones. However, I have to take medication every 24 hours. I use the iPhone alarm to set a time. Is there a way I can adjust it so it goes off whenever it is, say 10pm in US eastern time zone even if I'm in another time zone and my iphone clock is local time?
    thanks!

    Hi, ralphsen01-
    You can do this using window.scrollTo():
    http://stackoverflow.com/questions/3163615/how-to-scroll-html-page-to-given-anchor-using-j query-or-javascript
    Please note that when you embed an Animate OAM into Muse, you're in effect putting it into an iframe.  Therefore, you need to call the parent window.  You can get more information on this by searching for "iframe to parent communication" in a search engine.
    Hope this helps,
    -Elaine

Maybe you are looking for

  • Moving photos and associated tags, etc. to a new computer

    I have just updated APE-7 to APE-11 on my old computer which is running Windows 7.    The transition went well.   All photos and tags moved seamlessly to the new programs format.   I need advice on how best to transfer all of that to a new computer w

  • Max hdd size for ms-6140 ??

    anyone out there know the maximum size that the ms-6140 motherboard can handle?? its also called the 'micro ATX EX7' on some occasions. ive searched alot and cant find anything... bios has been flashed to most recent version, even though its only fro

  • Ads soap error

    if i execute adobe form in tcode sfp there is a soap error with adobe document services

  • PSE 10 organizer changing date times of photos

    I have been having an issue since PSE9 which continues into PSE 10 organizer. After scaning photos and saving into organizer it will not allow assingment of jsut a year or a year month. If I take an old family photo and change date (scanned date) to

  • Refresh DSV - why does it keep indicating it "Added" things, when its already been done? (repost from DW forum)

    Note to moderator(s): Please remove the other post https://social.msdn.microsoft.com/Forums/sqlserver/en-US/d4e30da8-5234-4373-963f-c165b99f8df2/bids-2008-refresh-dsv-why-does-it-keep-indicating-it-added-things-when-its-already-been-done?forum=sqldat