473,385 Members | 2,044 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,385 software developers and data experts.

passing retirned value from Javascript to PHP

Hi,
how can I pass the returned value from Javascript to PHP?
I have:

------------------------------------------------------------------------
------

if ( x>y) {
echo '<script language="JavaScript">';
echo 'confirm(\''.$itemname.' requires '.$optionname.' Do you want
to add '.$optionname.'?\')</script>';

<I want to return the true/false value returned when user presses
OK/Cancel, to PHP code>

}

------------------------------------------------------------------------
------

Thanx
Jul 17 '05 #1
2 3509
On Thu, 11 Mar 2004 14:04:42 GMT, "Xerxes" <as*******@hotmail.com> wrote:
how can I pass the returned value from Javascript to PHP?
I have:

------------------------------------------------------------------------
------

if ( x>y) {
echo '<script language="JavaScript">';
echo 'confirm(\''.$itemname.' requires '.$optionname.' Do you want
to add '.$optionname.'?\')</script>';

<I want to return the true/false value returned when user presses
OK/Cancel, to PHP code>

}

------------------------------------------------------------------------
------


Is this triggered by submitting a form? If so, use Javascript to modify the
form to introduce an <input type="hidden"> element, or set the value of an
existing <input> element, so it's available to the PHP script it's submitted
to.

Since the only way to get something run by a client is to post it to another
PHP script, it can't be done 'inline', so it's off-topic here, try a Javascript
group. Followups set to comp.lang.javascript.

--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool
<http://www.andyh.co.uk> / <http://www.andyhsoftware.co.uk/space>
Jul 17 '05 #2
> >how can I pass the returned value from Javascript to PHP?
I have:
Since the only way to get something run by a client is to post it to

another PHP script, it can't be done 'inline', so it's off-topic here, try a Javascript group. Followups set to comp.lang.javascript.


Actually, if you are determined to do this, it CAN be done in PHP, and so it
is on topic. It is just rather convolulted.

Here is the outline. Assume that you have a form (or something). When you
change the value in something, like a drop down box, you would like to
change the values of another drop down box, BUT, you want to run server side
code to accomplish this. I use this technique, a lot, to perform dynamic
drop down box generation, ON THE SAME screen, fom the server, WITHOUT a
refresh.

On the page you want this to happen:
Include a form with the drop down box that the user can select from. This
drop down box has an "onChange" event attached to it. One I use looks like
this:
function doDB () {
document.input.tbl.disabled = false;
if (needClear) {
removeAll(document.input.tbl);
document.input.tbl.disabled = true;
}
var theElement = document.input.db;
var theIndex = theElement.selectedIndex;
var theValue = theElement.options[theIndex].value;
removeAll(document.input.tbl);
addOption (tbl', 'Select', 'NONE');
top.hidden.document.location =
"../include/loaders/gettables.php?thedb=" + theValue;
}

Here is the other routine that are used, just for your reference:
function removeAll(theElement) {
var selectLen = theElement.length;
for (var i = 0; selectLen > i; i++) {
removeLast(theElement);
}
}

I use a boolean called needClear that determines if I should erase the
contents (based on other form elements that the user might check)

(the routine gettables.php is the one that does all the server side stuff.
You will need to write your own that does what you want, so I will not
include it. However, you also need this routine to return the values: this
is the strip of code that does that. I assume that you are capable of
putting something into $tables <grin>:
echo "<script>\n";
foreach ($tables as $key => $value) {
echo "parent.addOption ('tbl', '" . $value . "', '" . $key . "');";
}
echo "</script>\n";

Include another drop down box (preferably inactive for the user's sake)
where the dynamic values will go.
Include a blank inline frame, hidden, somewhere on the page. The one I use
looks like this:
echo "<div id=\"iframe\" style=\"display:none;\">\n";
echo "<iframe src=\"../blank.php\" name=\"hidden\"></iframe>\n";

The source for blank.php looks like this:
<htm>
<head>
<title></title>
</head>
<body>
</body>
</html>
(spiffy, eh?)

That should get your going. Dynamic population of drop down list boxes,
WITHOUT a refresh, and using client-side data. I lifted these routines and
adapated them from various places across the internet. I just don't like the
word "impossible" <grin>

Enjoy!
david

Jul 17 '05 #3

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

Similar topics

12
by: Kevin Lyons | last post by:
Hello, I am trying to get my select options (courses) passed correctly from the following URL: http://www.dslextreme.com/users/kevinlyons/selectBoxes.html I am having difficulty getting the...
3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
9
by: Max | last post by:
I'm new with Javascript and can't seem to figure out what I'm doing wrong here as I'm not able to pass a simple variable to a function. In the head of doc I have: <script...
6
by: ged | last post by:
Hi, i am a oo (c#) programmer, and have not used javascript for a while and i cant work out how javascript manages its references. Object References work for simple stuff, but once i have an...
5
by: Steve | last post by:
Hi, I currently have a problem passing a variable value from one page to another. Once a form submit button is pressed java pops up a window and displays some information. The problem being is...
5
by: sfeher | last post by:
Hi All, I need to call a function(loaded with appendChild) for which I have the name as a string. .... var fnName = 'fn1'; var call = fnName + '('+ param +' )'; eval(call);
4
by: Nathan Sokalski | last post by:
I am a beginner with AJAX, and have managed to learn how to use it when passing single parameters, but I want to return more than one value to the client-side JavaScript function that displays it....
5
by: moni | last post by:
Hi.. I am trying to use javascript for google maps display. If I call the javascript function from my aspx file I use: <input type="text" id="addresstext" value="Huntington Avenue,...
5
by: aelred | last post by:
I have a web page where a member can open up a chat window (child window) with another member. - From there the member can also navigate to other web pages. - From other pages in the site, they...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.