473,386 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How to retrieve javascript object value in PHP ?

I want to set an initial text in a TEXTAREA based on the value selected
in an earlier SELECT box in the same document.

I tried something like

$init_text=set_init_text() ;
<TEXTAREA>
<?php echo $init_text ; ?>
</TEXTAREA>

function set_init_text() {
return <script>
document.forms[0].SelectBox.options[document.forms[0].SelectBox.selectedIndex].value
</script }
But I get a php syntax error with the <script> tag.

What's the correct way to do it ?

Jan 9 '06 #1
3 1930
Following on from 's message. . .
I want to set an initial text in a TEXTAREA based on the value selected
in an earlier SELECT box in the same document. Sorry but you have completely mis-understood how php works.

Client browser - "Web server! send me this resource"
Web server - "OK" [ FX rummages around while running AND FINISHING a php
script] "Here it is now - Thank you and have a nice day"
Client browser - "User I will show you the HTML just sent to me by the
server"
Javascript = client side
php = server side. [ie no interaction]


I tried something like

$init_text=set_init_text() ;
<TEXTAREA>
<?php echo $init_text ; ?>
</TEXTAREA>

function set_init_text() {
return <script>
document.forms[0].SelectBox.options[document.forms[0].SelectBox.selectedInde
x].value
</script }
But I get a php syntax error with the <script> tag.

What's the correct way to do it ?


--
PETER FOX Not the same since the pancake business flopped
pe******@eminent.demon.co.uk.not.this.bit.no.html
2 Tees Close, Witham, Essex.
Gravity beer in Essex <http://www.eminent.demon.co.uk>
Jan 9 '06 #2
On Mon, 09 Jan 2006 09:32:42 +0000, Peter Fox wrote:

No interaction, but php can quite happily write js just as easily as it
can write html/xhtml/xml/...
Following on from 's message. . .
I want to set an initial text in a TEXTAREA based on the value selected
in an earlier SELECT box in the same document.

Sorry but you have completely mis-understood how php works.

Client browser - "Web server! send me this resource" Web server - "OK"
[ FX rummages around while running AND FINISHING a php script] "Here it
is now - Thank you and have a nice day" Client browser - "User I will
show you the HTML just sent to me by the server"
Javascript = client side
php = server side. [ie no interaction]


I tried something like

$init_text=set_init_text() ;
<TEXTAREA>
<?php echo $init_text ; ?>
</TEXTAREA>

function set_init_text() {
return <script>
document.forms[0].SelectBox.options[document.forms[0].SelectBox.selectedInde
x].value
</script }
But I get a php syntax error with the <script> tag.

What's the correct way to do it ?


Jan 9 '06 #3
Ike
Do an HTTP POST (or GET) of a form, where you send the object from
Javascript, calling the same page to rerender. When the page loads, in php,
check if the value was sent. Suppose I have a js variable 'x'. I then put it
in a hidden text field say, on a form, and POST the form.

When the page reloads, it tests to see if x has been "set" in javascript
(i.e. POSTED):

$x = $_POST['x'];

if $x =="" then it is the first time the form was loaded and x has not been
set in js. (or, a subsequent time for loading the form after a POST and x
was never set in js). You may want to check too if x==null, not sure if it
is null or "". -Ike
Jan 9 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Eugfene | last post by:
I have the following function in a html file: function selectEdit(fileID, processCode, processID, fileName,fileDesc) { document.forms.recordID.value = fileID; document.forms.processor.value =...
2
by: Cheryl | last post by:
Hi, I have encounter a problem.Language use is C#. I would like to open a new window (is a modal window, where I m not able to switch from parent window after this window is open)from the parent...
5
by: ggk517 | last post by:
We are trying to develop an Engineering application using PHP, Javascript with Informix as the back-end. Is it possible to retrieve data using Javascript but by accessing the Database. Say...
11
by: Patricio | last post by:
Hello all I open a PopUp that receives two variables (values). This PopUp must return a value as well. How can I retrieve this value? Thanks a lot.
2
by: tomromanul | last post by:
Hi all, I built a Windows Froms user control and I use it in IE 6+. It functions properly (it displays properly in IE and executes code, such as displaying a message box), except that in the web...
6
by: ashok.dhananjeyan | last post by:
Hi, Actually , I wrote one javascript to retrieve the name of the form in one particular page. what i did in this page is, <script> function checkbutton() {
1
by: yootaeho | last post by:
Hi, I have the following script <%@LANGUAGE=Javascript%> <% var myClass = new LoginInfo(); myClass.sessionID = "1321312131"; Response.Cookies("testingCookies") = myClass; var...
4
by: divina11 | last post by:
I'm trying to retrieve the options below, depending on the one the user selects, I'm bulliding a Calculator Program where user inputs 2 values via input box and then selects an operation: Code:...
21
by: giandeo | last post by:
Hello Experts. Is it possible to retrieve the value from a populated pull down menu from a database and then use that value to access the same database to get the related fields. Example: ...
2
by: phpachu | last post by:
Hi, I hav created a group of textboxes using a loop and its names are unique and names are assigned using variable ( like <input type=text name=$name1>). Then How can i retrieve the values in...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.