Passing parameters form a JS page to a PHP page

Javascript coding ..

Moderators: macek, egami, gesf

Post Reply
User avatar
gesf
Moderator
Moderator
Posts: 1717
Joined: Sun Dec 29, 2002 5:03 am
Location: Portugal / Sweden
Contact:

Post by gesf » Thu May 27, 2004 10:32 am

Well, the javascript code you´re using is to load an external .js file to your page. So it´s kindly passing nothing through url!

Use this one!
You ´ll print/use it where/when you need to send some url, or the url to be replaced with:

Code: Select all

<script language="JavaScript">
window.location.replace("http://full/url/to/ecriture21.php?parm1=");
</script>


This is like using php's header() function!

User avatar
ruturajv
php-forum Super User
php-forum Super User
Posts: 1280
Joined: Sat Mar 22, 2003 9:42 am
Location: Mumbai, India
Contact:

Re: Passing parameters form a JS page to a PHP page

Post by ruturajv » Thu May 27, 2004 7:39 pm

francois wrote:

Code: Select all

   <script language="JavaScript" 
   src="ecriture21.php?parm1=" + page>
   </script>



Is your javascript variable 'page' have any contents... ?

User avatar
gesf
Moderator
Moderator
Posts: 1717
Joined: Sun Dec 29, 2002 5:03 am
Location: Portugal / Sweden
Contact:

Post by gesf » Tue Jun 01, 2004 6:42 am

Buááá! Don´t do me that! Isn´t Jesf... but Gesf...!!

Joke!
Ok, that code you were using is to call a external .js file!
Why!? And... what usage would have!?
Well, theres no difference having the code in a external file or inside the html code, but if you have a lot of javascript code... it would be cleaner/better having it in another file!

Yes, it is to call javascript code.
Never forget this: Javascript is client-side scripting, unlike php witch is server-side scripting!
However, it´s possible to 'interact' with both (not directly), anyway you need to understand this concept and how it could be done.
Let´s say you would use php to do all you have to do before the page is loaded/shown!

For your particular case (sending stuff through url), let´s see two differente examples!

In this first, we will set a variable in server to be catch by javascript when the page is 'shown':

Code: Select all

<?php
$name = 'Maria';
?>

// Will print Maria
<script language="JavaScript">
  document.write("<?php echo $name; ?>");
</script>

<?php
// Contunie with the php code
?>


In this next, we will send a variable through url with javascript, to be catch by php when the pages gone to be loaded in server (example):

Code: Select all

<?php

/*
This php code will be loaded just if a variable section is passed through url, don´t matter the scripting language!
*/

if(isset($_GET['word'])){
echo $word; // Output maria
}
?>

<script language="JavaScript">
  window.location.replace("http://www.yoursite.com/thisfile.php?word=maria");
</script>

// Contunie with code


Well, hope you understand, maybe this isn´t the best example.
See this related post !

Anyway, for your last post, can you show/tell me what you´re planning to do!?

Cheers,
Gesf

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests