Results 1 to 8 of 8
  1. #1
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    austin, Texas, USA
    Posts
    1,029
    Thanks
    0
    Thanked 0 Times in 0 Posts

    .js include file for holding validation code

    I'm working on finalizing a suite of validation code for a website project and noticed that there's a way to wrap all the code into an include file and just reference it for each form. this sounds *a lot* easier than maintaining a lot of redundant code in various forms in the <header > block.

    I'll start trying to implement this using naivet

  2. #2
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    Cincinnati, Ohio, USA
    Posts
    7,089
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: .js include file for holding validation code

    You do not need to configure the server to support JavaScript includes. Simply reference the source file in your <HEAD> element thus: <pre><script language="Javascript" src="/directory/script.js"></script></pre>

    -Mark

  3. #3
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    austin, Texas, USA
    Posts
    1,029
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: .js include file for holding validation code

    yeah i've already got it working well & have named the include file 'validate.jsp' -- don't know if the extension means that much?

  4. #4
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    Cincinnati, Ohio, USA
    Posts
    7,089
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: .js include file for holding validation code

    I think the extension can be pretty much anything - it's the declaration of the script language that matters, it tells the server how to parse whatever follows.
    -Mark

  5. #5
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    austin, Texas, USA
    Posts
    1,029
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: .js include file for holding validation code

    that's what I figured. anyway, I put all my validation code into an include file and with the include line on the forms all works wonderfully!

    Yaaayyy!

    One thing I *really* liked - or discovered and used - is you can use RegExp to limit the type and length of data in a field, which is way cool. So, for example a zip code has to show result True for:
    <font face="Georgia">
    /^(d{5}|d{9}|d{5}-d{4})$/;
    </font face=georgia>
    which will happen if you input 5 digits only, 9 digits only, or the canonical 78701-1234. Any other format doesn't pass, and you don't have to fuss with evaluating the length of the input string or hunt for the '-' separately. nifty!

  6. #6
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: .js include file for holding validation code

    FYI: JSP extension implies Java Server Pages, although the browser doesn't usually care what extension is used.
    Most commonly, you'll just see .JS as the extension for Javascript files.

  7. #7
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: .js include file for holding validation code

    If the server is JSP aware, this might be confusing. (I don't know enough Java to know what would happen when the executable processes your file.) I think you're better off using .js as nature intended.

  8. #8
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    austin, Texas, USA
    Posts
    1,029
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: .js include file for holding validation code

    i have conformed to natural standards and expectations. (hopefully!)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •