Current location: Hot Scripts Forums » Programming Languages » PHP » php and javascript together?


php and javascript together?

Reply
  #1 (permalink)  
Old 08-25-03, 10:46 PM
gamextremer2003 gamextremer2003 is offline
Newbie Coder
 
Join Date: Jul 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
php and javascript together?

How can I make or send information to php from javascript? Maybe I need MySql help..I dunno.

Here's my problem, I'll make it really simple so that it won't take too much of your time to understand.

HTML----

link to external script
script = javascript src=1.js

JAVASCRIPT----

Make random number
Store number either by making a new array or num = randomnum and setting +num+ to the random number

PHP----
Write $num to text file.


and while all this is going, the page has not lost it's focus on the HTML file. Basically what I mean is that all this happens in the background.

How exactly would I be able to do this? Any help would be greatly appreciated. Thank you.
__________________
Gamex
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 08-26-03, 06:40 AM
ermau's Avatar
ermau ermau is offline
Wannabe Coder
 
Join Date: Aug 2003
Location: Florida, USA
Posts: 240
Thanks: 0
Thanked 0 Times in 0 Posts
Maybe you could have javascript open a window in the background running a php script using a GET variable to pass the $num variable?
__________________
PHP / mySQL Developer
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 08-27-03, 03:57 AM
Skeleton Man Skeleton Man is offline
Community Liaison
 
Join Date: Jun 2003
Location: Australia
Posts: 406
Thanks: 0
Thanked 0 Times in 0 Posts
To ask a stupid question, why do you want to do something like that in Javascript, when it's easy to get a random number in PHP anyway ?
__________________
Chris (aka Skeleton Man)
ProgrammingTalk's Perl/PHP Moderator !
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 08-27-03, 06:22 AM
ermau's Avatar
ermau ermau is offline
Wannabe Coder
 
Join Date: Aug 2003
Location: Florida, USA
Posts: 240
Thanks: 0
Thanked 0 Times in 0 Posts
Agreed, but he may need it to be done a number of times without reloading the page, doubtful but it's possible.
__________________
PHP / mySQL Developer
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 11-05-03, 03:26 PM
Sonic The Edge Hog Sonic The Edge Hog is offline
New Member
 
Join Date: Nov 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
I've got a similar problem..

I have a javascript function that takes an array, but the array is filed with php vars... how do i get the js vars to have the php var values?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 11-06-03, 03:18 PM
insane insane is offline
New Member
 
Join Date: Nov 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
There are two issues here:

1. How to put PHP variables into javascript
2. How to put javascript variables back into PHP

Here is how I have done it...

1. Putting PHP variable into your javascript is easy, just echo them into the script wherever you normally would declare your script variables.

2. Putting the variables back into PHP is the tricky part. You need a script that will take the javascript variables and put them into variables that will be posted back to the server when the form is submitted.


Below is a simple example...
Code:
<html>
<head>
	function preProcess()
	{  
		document.tournament.post1.value = document.tournament.var1.value;
	}

</head>
<body>

	<form name="tournament" id="tournament" method="post" action="bracketsave.php" onSubmit="preProcess()">
	<input type="hidden" name="post1">

	// some js goes here using the variable var1

	</form>
</body>
</html>
You can find a more complex example here...

http://beta.experts-exchange.com/Web..._20587955.html
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP to JAVASCRIPT: 2D Array Conversion 770 PHP 4 11-05-03 03:47 PM
Javascript vs PHP, problem with arrays Chuff JavaScript 0 10-03-03 05:01 AM
Ad management and optimisation using php surebetdmg PHP 0 08-28-03 07:45 PM
looking for somthing in javascript Henry Script Requests 0 07-25-03 03:07 AM
edit php in Squirrelmail jrcortrightiii PHP 1 07-10-03 03:08 PM


All times are GMT -5. The time now is 10:16 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.