472,986 Members | 2,952 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,986 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 3484
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...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

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.