Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 10 of 10
  1. #1
    Junior Member
    Join Date
    Oct 2003
    Location
    Barcelona
    Posts
    20
    Member #
    3732
    I have an external file '.js' to validate an e-mail field in a form and I don't know how can I access it from the code of the page.
    The function into the ‘.js’ file is named ‘checkfield(form1)’ and I am trying to access it from the code page with this syntax:

    <a href="new_user2.asp" onClick="checkfield(form1)">To send data</a>

    With this syntax I try to trigger the ‘checkfield(form1)’ function and then go to the next page. How can I do it?


    Cesar

  2.  

  3. #2
    Banned
    Join Date
    Oct 2003
    Posts
    236
    Member #
    3555
    reference it in your script tag

  4. #3
    Senior Member DeltaWeb's Avatar
    Join Date
    Oct 2003
    Location
    U.S. of A
    Posts
    159
    Member #
    3592
    yea, thats all refrence it. /whatever, if its external thats how you get it. i suspect your using a free server and have a file manager and have to link to another file on the server.
    KRS-ONE....Knowledge Reigns Supreme Over Nearly Everyone....

  5. #4
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    Code:
    <html>
        <head>
            <script language="javascript" src="my_script.js" />

  6. #5
    Senior Member skrlin's Avatar
    Join Date
    Apr 2003
    Location
    Illinois
    Posts
    562
    Member #
    1063
    Originally posted by transio
    Code:
    <html>
        <head>
            <script language="javascript" src="my_script.js" />
    Expanding on this:

    If your .js file is hosted on a seperate server, then reference it this way:
    Code:
    <html>
        <head>
            <script language="javascript"
              src="http://www.server.com/path/to/js/my_script.js" />
    - Brian

  7. #6
    Junior Member
    Join Date
    Oct 2003
    Location
    Barcelona
    Posts
    20
    Member #
    3732
    I use Personal Web Server, an ASP VBScript page and I work in the same pc.

    I already have written the script reference ‘<script language="javascript" src="my_script.js" />’ into the head section but it does not run.

    Function in ‘my_script.js’ file:
    <SCRIPT LANGUAGE=”JavaScript”>
    function checkfield(form1)
    {…..
    </SCRIPT>

    Into the page:
    <script src="my_script.js">
    </script>

    <a href="new_user2.asp" onClick="checkfield(form1)">To send data</a>


    The ‘my_script.js’ file is situated joint with others ‘.asp’ and ‘htm’ pages in the corresponding folder ‘C:/My_website/my_script.js’, and it is not in the server folder. Anyway I have already tried it saving the ‘my_script.js’ into the server folder ‘C:/Inetpub/scripts/my_script.js’ and it continue doesn’ t run.

  8. #7
    Senior Member skrlin's Avatar
    Join Date
    Apr 2003
    Location
    Illinois
    Posts
    562
    Member #
    1063
    Your .js file (and .js files in general) should not have any html tags in it (ie <script></script>), it should only contain straight javascript code. If you remove any script tags from the js file it should work provided you have referenced it correctly as you said you have.
    - Brian

  9. #8
    Junior Member
    Join Date
    Oct 2003
    Location
    Barcelona
    Posts
    20
    Member #
    3732
    Perfect! now runs well. :classic:

    After click the link below if the field is not filled correctly the alert message appears, but after 'accept' the message instead of to remain in the page to correct the mistake it goes to the next page.

    How can I write the code so that after to accept the alert message the page remains there, and if it no mistakes are found go to the next page?

    My code now:
    <form name="form1" action="" method="post">
    ..
    </form>
    ..
    <a href="new_user2.asp" onClick="checkfield(form1)">TO SEND DATA</a>

  10. #9
    Senior Member nocloset's Avatar
    Join Date
    Sep 2003
    Posts
    108
    Member #
    3228
    <a href="new_user2.asp" onClick="return checkfield(form1);">TO SEND DATA</a>

    Then have your checkfield function return false if the field is not filled in correctly.

  11. #10
    Junior Member
    Join Date
    Oct 2003
    Location
    Barcelona
    Posts
    20
    Member #
    3732
    Good!
    I have been explained something about the 'return' statement but I didn' t remember. Thank you vm

    Cesar


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 07:01 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2020 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com