Jump to content

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()

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.