aeroswat Posted January 11, 2010 Share Posted January 11, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/188115-using-javascript-to-call-php-function/ Share on other sites More sharing options...
mikesta707 Posted January 11, 2010 Share Posted January 11, 2010 theoretically, yes Quote Link to comment https://forums.phpfreaks.com/topic/188115-using-javascript-to-call-php-function/#findComment-993168 Share on other sites More sharing options...
aeroswat Posted January 11, 2010 Author Share Posted January 11, 2010 theoretically, yes it does work Now I'd like to know... my host inserts extra ad code at the end of the page and it's including that in the data... how would i get rid of that? don't want it showing up in the textbox too like it is Quote Link to comment https://forums.phpfreaks.com/topic/188115-using-javascript-to-call-php-function/#findComment-993174 Share on other sites More sharing options...
mikesta707 Posted January 11, 2010 Share Posted January 11, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/188115-using-javascript-to-call-php-function/#findComment-993183 Share on other sites More sharing options...
aeroswat Posted January 12, 2010 Author Share Posted January 12, 2010 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() Quote Link to comment https://forums.phpfreaks.com/topic/188115-using-javascript-to-call-php-function/#findComment-993636 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.