#1
  1. No Profile Picture
    Contributing User
    ASP Good Citizen (1000 - 1499 posts)

    Join Date
    Feb 2005
    Posts
    1,285
    Rep Power
    40

    call external JS Function from html


    I am trying to call a function that is my External JS page...this function needs to be called onClick of a radio button or onChange etc...

    I need this to run when I change the radio buttons...and external to the HTML page.
    Please help

    HTML
    Code:
    	<!-- Reference the js page containing all the Java Script code -->
    	<script src="js/externalPage.js"></script>
    
    
    <form id="myform">
        	<input type="radio" name="drink" id="radioOne" onClick="tests();" checked value="tea"/> <label for="radioOne">Tea</label> <br />
        	<input type="radio" name="drink" id="radioTwo" onClick="tests();" value="coffee"/> <label for="radioTwo">Coffee</label> <br />  
    </form>
    External JS Page
    Code:
    	function tests(){
    		alert("fdkjgdjfdg");
    	}
  2. #2
  3. No Profile Picture
    Contributing User
    ASP Good Citizen (1000 - 1499 posts)

    Join Date
    Feb 2005
    Posts
    1,285
    Rep Power
    40
    I was able to get it to work SORT OF....

    But this does not work on the first selection of the radio buttons....you have to hit twice because of the onChange I Presume.
    How do I get this to work on the first selection of the radio buttons?


    Code:
    <form id="myform">
        	<input type="radio" name="drink" id="radioOne" value="tea"/> <label for="radioOne">Tea</label> <br />
        	<input type="radio" name="drink" id="radioTwo" value="coffee"/> <label for="radioTwo">Coffee</label> <br />
    </form>
    Code:
    	on(dojo.byId('myform'), "click", tests);
    
    	function tests(){
    
            var ch = document.getElementsByName('drink');
    
    		for (var i = ch.length; i--;) {
    		    ch[i].onchange = function() {
    		        alert(this.value);
    		    }
    		}
    
    	}
  4. #3
  5. No Profile Picture
    Contributing User
    ASP Good Citizen (1000 - 1499 posts)

    Join Date
    Feb 2005
    Posts
    1,285
    Rep Power
    40
    I was able to get it working by moving the javascript code into the OnLoad Function

Similar Threads

  1. Call vbscipt function on html onsubmit
    By dandeliondream in forum ASP Development
    Replies: 4
    Last Post: April 15th, 2010, 05:10 AM
  2. HTML form will not call my js validation function.
    By rschwa01 in forum HTML, JavaScript And CSS Help
    Replies: 1
    Last Post: May 1st, 2009, 11:02 PM
  3. Included External html file
    By JustXtreme in forum ASP Development
    Replies: 1
    Last Post: March 12th, 2008, 09:35 AM
  4. Access HTML document from external JS file
    By baseballdude_ in forum HTML, JavaScript And CSS Help
    Replies: 15
    Last Post: June 28th, 2007, 03:11 AM
  5. Replies: 1
    Last Post: August 4th, 2003, 03:43 PM

IMN logo majestic logo threadwatch logo seochat tools logo