Jump to content

Using javascript to call php function


aeroswat

Recommended Posts

I need to use a javascript function in order to call a php function and manipulate the resulting string. I've sort of done this with AJAX and $.post but I copied an example in order to do that. I'm not sure if I could replicate the same thing and return a string in some way like the following... here's the javascript function

 

	function lookup(inputString) {
	if(inputString.length == 0) {
	} else {
		$.post("returnstuff.php", {ss: ""+inputString+""}, function(data){
			if(data.length >0) {
				document.getElementById("thetextbox").value=data;
			}
		});
	}
} 

 

Then have returnstuff.php be a php file that echo's the result of a field from a database query... would this work for what i want it to do which is the following:

 

Input a code # in one textbox, press a button, have the php file query the database to find the definition for that code # and print the definition in a different text box.

Link to comment
https://forums.phpfreaks.com/topic/188115-using-javascript-to-call-php-function/
Share on other sites

is it the same string every time? if so a simple str_replace will do. if not a more complicated preg_replace using regex would probably suffice. a sample of what the extra code looks like would help

 

i echo'd #STOP# after what my code was doing and then just used str.search() to find the position of the #STOP# and used only the stuff before it with str.substr()

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.