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:

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

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();
	if(req){
		req.onreadystatechange = function(){
			if(req.readyState == 4){
				if(req.status == 200){
					document.getElementById(var2).innerHTML = req.responseText;
				}else{
					alert("There was a problem while using XMLHTTP:\n"+req.statusText);
					}
			}
		}
		req.open("GET", strURL, true);
		req.send(null);
	}
}

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!

Recommended Answers

All 2 Replies

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.