dcsimg
www.webdeveloper.com
Results 1 to 3 of 3

Thread: call a Javascript from an external page

  1. #1
    Join Date
    Oct 2017
    Posts
    2

    call a Javascript from an external page

    I have a webpage with the multiple javascripts and form(s) requesting user input. As the webpage html is getting too busy I am attempting to separate the javascript to its own page.

    SAMPLE CODE ON MY CURRENT WEBPAGE
    HTML Code:
    <body
    <script type = "application/javascript">
    function Opencorporates(selection){
    
    window.open("https://api.opencorporates.com/v0.4/companies/search?q="+selection.value+"&format=xml")
    
    }
    </script>
    
    
    <form onsubmit = "Opencorporates(query)">
    <h2>Opencorporates:</h2> <input type="text" placeholder="Company Check" name="query"><input type = "submit" value = "submit" >
    </form>
    </body>
    MY ATTEMPT AT CALLING THE JAVASCRIPT (unsuccessful)

    I have saved the javascripts javascript_samples.js but I am unable to get the query to work.

    Code:
    function Opencorporates(selection){
    
    window.open("https://api.opencorporates.com/v0.4/companies/search?q="+selection.value+"&format=xml");
    
    }
    I am unsure how to call the saved script from the webpage.

    HTML Code:
    <body>
    <form name="search" onsubmit = "return Opencorporates();">
            <input type="text" placeholder="friends" name="query">
            <input type = "submit" name="submit" value = "submit" ></form>
    </body>
    I hope this makes sense and thank you in advance for your help.

  2. #2
    Join Date
    Oct 2017
    Posts
    2
    Quick Update to my query I also have this code in the body of my webpage

    HTML Code:
    <script src="javascript_samples.js"></script>

  3. #3
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    5,522
    --> JavaScript Frameworks like JQuery, Angular, Node <--
    ... and please remember to wrap code with forum BBCode tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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