4 Replies - 619 Views - Last Post: 05 August 2011 - 07:18 AM

#1 itaprz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 16-April 10

Processing both Javascript and PHP

Posted 03 August 2011 - 12:16 PM

hey there,

I have a form which sends a string to php file which processing the string and echoes the new string , and there's another javascript file which uses the new string and displaying it without refreshing the page.

Both files are working but I don't know how to combine them so the string will be first proceeded in the php file and then then the javascript file will use it.

Any suggestions?

Thanks in advance

This post has been edited by itaprz: 03 August 2011 - 12:17 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Processing both Javascript and PHP

#2 maniacalsounds  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 117
  • View blog
  • Posts: 472
  • Joined: 27-June 10

Re: Processing both Javascript and PHP

Posted 03 August 2011 - 12:34 PM

Hmm? Simple use Javascript to activate the PHP script, and make it run through. Save the response text in a variable, and pass it to the Javascript function that you want to use it in.

I could give a better example if you show some code.

Thanks :)
Was This Post Helpful? 0
  • +
  • -

#3 magiscoder  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 12
  • Joined: 29-July 11

Re: Processing both Javascript and PHP

Posted 03 August 2011 - 12:39 PM

Sounds like you're having trouble displaying a Javascript value with PHP. If that's the case, you don't need to do anything fancy, you just have to be careful with what you display.

So say you have $myString that you want to do stuff with in Javascript. For example, you want to pass it into a JS function myFunction:

<?php echo '
<script type="text/javascript">
var result = myFunction('.$myString.');
</script>
';
?>


Note the concatenation of strings going on in the third line.

This post has been edited by magiscoder: 03 August 2011 - 12:40 PM

Was This Post Helpful? 0
  • +
  • -

#4 itaprz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 16-April 10

Re: Processing both Javascript and PHP

Posted 03 August 2011 - 04:47 PM

View Postmaniacalsounds, on 03 August 2011 - 12:34 PM, said:

Hmm? Simple use Javascript to activate the PHP script, and make it run through. Save the response text in a variable, and pass it to the Javascript function that you want to use it in.

I could give a better example if you show some code.

Thanks :)



first of all- thanks for helping
now,i'll try to be more clear-

There's a file called main.php which recieve the user input from the form and then proccess the string and echoes the new string.
Moreover, there's the loadlist.js file which is goal is to retrive the proceeded string from main.php and then display it without refreshing the page.

I don't know how to combine between the files and i'd like you the suggest a solution please.
Was This Post Helpful? 0
  • +
  • -

#5 codeprada  Icon User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 948
  • View blog
  • Posts: 2,357
  • Joined: 15-February 11

Re: Processing both Javascript and PHP

Posted 05 August 2011 - 07:18 AM

Use Ajax.
You can find a tutorial here.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1