Javascript help

(4 posts) (2 voices)

Tags:

  1. ajdjackson, Member

    Hi

    I wish to check certain user input fields for data validity before the linked update report executes.
    For example I have a date field that needs to be checked for valid dates. The JavaScript I hope to use is:

    function checkdate(input){
    var validformat=/^\d{2}\/\d{2}\/\d{4}$/ //Basic check for format validity
    var returnval=false
    if (!validformat.test(input.value))
    alert("Invalid Date Format. Please correct and submit again.")
    else{ //Detailed check for valid date ranges
    var monthfield=input.value.split("/")[0]
    var dayfield=input.value.split("/")[1]
    var yearfield=input.value.split("/")[2]
    var dayobj = new Date(yearfield, monthfield-1, dayfield)
    if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield))
    alert("Invalid Day, Month, or Year range detected. Please correct and submit again.")
    else
    returnval=true
    }
    if (returnval==false) input.select()
    return returnval
    }

    I'm trying to check the date by using the following:

    select 'dbr.editable', 7, 'sp_DBR_plot_bookdate_edit', 'inPL_ID=ID','inPL_Bookdate=Plot_BookDate','callbefore=checkdate';

    The 'callbefore' event doesn't do anything.

    Please can you give an example of how to call a JavaScript function?

    I have added the JavaScript code using select 'dbr.javascript' as well as pasting into the 'JavaScript/Help' input box.

    Many thanks

    Jake

  2. myDBR Team, Key Master

    Why not just use 'type=datepicker' to allow user to use datepicker for the input? You would not need to use JavaScript at all as date is handled automatically.

    Additionally, please note that user may select different date format in preferences so it might be confusing if you try to force another format to the user in update.

    As you do not show the actual query, we cannot tell if the Plot_BookDate is the date-column to be updated (what is the column 7)?

    Assuming you are updating the 'Plot_BookDate' column, you could use command:

    select 'dbr.editable', 'Plot_BookDate', 'sp_DBR_plot_bookdate_edit', 'inPL_ID=ID', 'type=datepicker';

    The sp_DBR_plot_bookdate_edit would have two parameters: one for the PL_ID and one for the updated date.

    --
    myDBR Team

  3. ajdjackson, Member

    Thanks that worked fine.

    I'm still interested in how to trigger data validity checks in user inputs. Say I have a integer field how do I check that a number has been inputted and not alpha characters before the update linked report runs and causes a database error?

    Jake

  4. myDBR Team, Key Master

    You really do not have to check for validity errors. myDBR will automatically convert the input value to the corresponding datattype value.

    You can check the value that it is in acceptable range within the update procedure. If it's not, you can reject the input and return the original value to the user.

    --
    myDBR Team


Reply

You must log in to post.