LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 01-05-2006, 04:15 AM   #1
ALInux
Member
 
Registered: Nov 2003
Location: Lebanon
Distribution: RHEL 5/CentOS 5/Debian Lenny/(K)Ubuntu Is Dead/Mandriva 10.1
Posts: 668
Blog Entries: 7

Rep: Reputation: 31
pass javascript variable to php


Hi ...I am using a javascript prompt dialog box to ask the user for data....but I am not able to get the results into PHP...

The code is here
http://pastebin.com/491495

"I only display the relevant parts..since everything is working fine except getting hte php variable to the server side"
 
Old 01-05-2006, 04:23 AM   #2
datbenik
Member
 
Registered: Dec 2005
Location: Holland
Posts: 39

Rep: Reputation: 15
Javascript is client-side.
PHP is server-side.

You can't do it this way. You may hava a look at the XmlHttpRequest object.
 
Old 01-05-2006, 07:53 AM   #3
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
As previously stated JavaScript is client side and php is Server side so you need to send the data from the browser to the client. This can be done by submitting a form (POST data) or by sending a new Http request(GET data) both of these will then generate a new HTML page.

Another alternative is to use Ajax that would mean that you only need php to send the modified page data.

graeme.
 
Old 01-05-2006, 09:32 AM   #4
ALInux
Member
 
Registered: Nov 2003
Location: Lebanon
Distribution: RHEL 5/CentOS 5/Debian Lenny/(K)Ubuntu Is Dead/Mandriva 10.1
Posts: 668
Blog Entries: 7

Original Poster
Rep: Reputation: 31
I certainly know that it can be done..and I know about the client-side and server side issues...and you dont need XML to do it
 
Old 01-05-2006, 10:13 AM   #5
ALInux
Member
 
Registered: Nov 2003
Location: Lebanon
Distribution: RHEL 5/CentOS 5/Debian Lenny/(K)Ubuntu Is Dead/Mandriva 10.1
Posts: 668
Blog Entries: 7

Original Poster
Rep: Reputation: 31
Ok the following worked:
Create a hidden form object...
Create a javascript function that writes the value of the form object thisform.formelement.value = javascriptvalue

Submit the form and retrieve the value

You might know that...but that is what I wanted
 
Old 01-05-2006, 10:28 AM   #6
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
No one said that you needed XML. What we were saying is that you need to send the data to the server. A form (POST data) is one way. Anyway it's good that you have sorted it out .

graeme
 
Old 01-06-2006, 06:20 AM   #7
ALInux
Member
 
Registered: Nov 2003
Location: Lebanon
Distribution: RHEL 5/CentOS 5/Debian Lenny/(K)Ubuntu Is Dead/Mandriva 10.1
Posts: 668
Blog Entries: 7

Original Poster
Rep: Reputation: 31
Smile

First, let me thank you all for your help..especially you graemef this is not the first time you help me out when Iam stuck...
I think I formulated my previous reply wrong...I should revise my netiquette paper :P. About the XML thing I was referring to the XmlHttpRequest note by datbenik.

Thanks Again
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pass a variable as an agruement for cut chipmanchu Programming 1 05-25-2005 11:39 AM
javascript variable in a form rksprst Programming 3 01-05-2005 04:34 AM
How to pass mysql query to a variable? chynna_v Programming 4 09-03-2004 05:09 AM
How to pass env variable to KDE? koyi Linux - General 0 09-03-2003 03:29 AM
Pass text to variable Zed Linux - Software 6 05-12-2003 03:02 PM


All times are GMT -5. The time now is 07:45 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration