Hi. I am trying to send the name of a file which is going to be launched for execution using a script from a *.js file. So in the original *.php file i have imported the *.js file like this:

<script type = "text/javascript" src = "getListsInfo.js"></script>

Then, i use the onclick event on a radio button to call the function form *.js file:

        <input type="radio" name="name1" value="value" id="name1_0" onclick="function(param1, param2)"/>

Now this is the script which calls the file which is going to be executed

function FUNCTION(param1, param2){	
	var strURL = "file.php?var1="+val1+"&var2="+val2;
	var req = getXMLHTTP();
		req.onreadystatechange = function(){
			if(req.readyState == 4){
				if(req.status == 200){
					document.getElementById(var2).innerHTML = req.responseText;
					alert("There was a problem while using XMLHTTP:\n"+req.statusText);
		req.open("GET", strURL, true);

The question is how can i transfer the name of the file (file.php) which is going to be executed by the script above (in the *.js file), from the html/php from which I call the function FUNCTION, into the same script (from the *.js file) as a parameter, to make it dynamic. Now i have to write different scripts in case I want to do the same for several files.

Hope its clear want I want to do. Thank you!

Edited by alexia_net: n/a

7 Years
Discussion Span
Last Post by alexia_net

You could do:

<script type="text/javascript" src="getListsInfo.php?filename=file.php"></script>

The getListsInfo.php would read the filename parameter and output (with a template so to speak) the requested js file (using echo).


Thank you. I have managed to add it as parameter in the onclick event in the html code, when i call the function.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.