tyooseph Posted September 28, 2007 Share Posted September 28, 2007 Hello, I have a <select> statement which calls a javascipt function, updCities(), upon 'onchange'. My HTML page is generated using php and the javascript is contained within <script> tags at the end of my php script. The function takes the selected value from the <select> statement and populates the <options> of other <select> statements on the same page. The function works fine as long as the javascript script is placed with <script> tags at the end of my php script. But, if I place the javascript script in an external file (.js) I get an 'object expected' error at the line containing the 'onchange' call function. I am not familiar with javascript. I did not generate the code below and need help understanding how to call an external function. How can I call an external javascript function? Does the name of the external file have to be the name of the function? How can I pass the value from the select statement to the external function? Does the <script> tags have to be within the <head> tags?? Thanks, and here's my script... //php document generating the HTML page ... <select name="county" id="county" size=1 onchange="updCities(); "> ... <script language="JavaScript" type="text/javascript" scr="www.arb.ca.gov/msprog/bus/rptg/js/droplists.js"></script> // droplists.js JavaScript Document var url = "getcities.php?county="; // passes value to php script that populates other select options ... function updCities() { if (!isWorking && http) { var county = document.getElementById('county').value; http.open("GET", url + escape(county), true); http.onreadystatechange = handleHttpResponse; isWorking = true; http.send(null); } } Quote Link to comment https://forums.phpfreaks.com/topic/71065-calling-external-javascript-function-from-within-html-generated-using-php/ Share on other sites More sharing options...
rarebit Posted September 28, 2007 Share Posted September 28, 2007 By including the js file, it is as if it is part of the same file, nothing extra or special needs to be done. I generally reference the file locally, e.g. <script language="JavaScript" type="text/javascript" scr="droplists.js"></script> n.b. this isn't the js forum Quote Link to comment https://forums.phpfreaks.com/topic/71065-calling-external-javascript-function-from-within-html-generated-using-php/#findComment-357326 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.