473,322 Members | 1,510 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,322 software developers and data experts.

Possible help with php/ajax call?

Fellow php'ers;

I am trying to make a call to a js function from within a php function based
on the selected value of an HTML select statement (whew!).

While the server side php program is getting called the variable being
passed is always empty. The following is my select statement from within
my php program which itself falls within a php function:

print "
<select name=\"_stcd\" id=\"_stcd\"
onchange=\"ajaxCallServer('http://".
$_SERVER['SERVER_NAME']."/cnl0d2.php?_selName=_gameid&_stcd=".$_stcd."')
>";
The valut of $_stcd SHOULD contain the value of the select item the user
selects. But its always blank.

The select option lines are generated from an array of values immediately
following this line.

As I've been searching, researching, re-reading my php books, javascript
books, etc for two days now, I thought it best to ask someone else.

Any ideas as to why this value is always blank?

Thanks all (my mind is fried!)

Bob

Nov 3 '08 #1
6 1831
Bob M escribió:
I am trying to make a call to a js function from within a php function based
on the selected value of an HTML select statement (whew!).
You cannot. This his how all this works: PHP runs on the web server, it
outputs a regular HTML document with possibly some bits of JavaScript
and it delivers this document to your web browser, which then parses the
HTML and runs the JavaScript code. Whatever PHP tutorial you read, this
is explained in the first chapter :-P
While the server side php program is getting called the variable being
passed is always empty. The following is my select statement from within
my php program which itself falls within a php function:

print "
<select name=\"_stcd\" id=\"_stcd\"
onchange=\"ajaxCallServer('http://".
$_SERVER['SERVER_NAME']."/cnl0d2.php?_selName=_gameid&_stcd=".$_stcd."')
>";
It's simple. This code runs in your computer, not in the server, thus
you cannot use PHP. You must use JavaScript to fetch the current value
of the <selectfield.
--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor al baño María: http://www.demogracia.com
--
Nov 3 '08 #2
"Ãlvaro G. Vicario" wrote:
Bob M escribió:
>I am trying to make a call to a js function from within a php function
based on the selected value of an HTML select statement (whew!).

You cannot. This his how all this works: PHP runs on the web server, it
outputs a regular HTML document with possibly some bits of JavaScript
and it delivers this document to your web browser, which then parses the
HTML and runs the JavaScript code. Whatever PHP tutorial you read, this
is explained in the first chapter :-P
>While the server side php program is getting called the variable being
passed is always empty. The following is my select statement from within
my php program which itself falls within a php function:

print "
<select name=\"_stcd\" id=\"_stcd\"
onchange=\"ajaxCallServer('http://".
$_SERVER['SERVER_NAME']."/cnl0d2.php?_selName=_gameid&_stcd=".$_stcd."')
>>";

It's simple. This code runs in your computer, not in the server, thus
you cannot use PHP. You must use JavaScript to fetch the current value
of the <selectfield.

Thanks - Got It! Duh, me!
Nov 3 '08 #3
Thanks - Got It! Duh, me!

So, does this NOW seem like it "should" be correct? I am getting a php
syntax error on the unexpected character of "["

print "
onchange=\"ajaxCallServer('http://"
$_SERVER['SERVER_NAME']."/cnl0d2.php?_selName=_gameid&_stcd="
+document.getElementById('_stcd').options[document.getElementById('_stcd').selectedIndex].value'')
>";


Nov 3 '08 #4
Bob M escribió:
So, does this NOW seem like it "should" be correct? I am getting a php
syntax error on the unexpected character of "["

print "
onchange=\"ajaxCallServer('http://"
There's a concatenation operator missing (aka dot) and some other typos.

It's very difficult to debug code written this way. Sometimes it's
easier to just end PHP mode and write HTML as is:

// ... some PHP
?>
<select name="foo" onclick="alert('Bar')">
<?php
// More PHP

$_SERVER['SERVER_NAME']."/cnl0d2.php?_selName=_gameid&_stcd="
+document.getElementById('_stcd').options[document.getElementById('_stcd').selectedIndex].value'')
>";
A couple of JavaScript tips:

* Don't write all your code in one line inside the onchange attribute:
use functions

* Your code is executed when printed, thus _stcd will not change. Try
something like:

onchange="fetchData(this)"

function fetchData(field){
var url = "/cnl0d2.php?_selName=_gameid&_stcd=" +
field.options[field.selectedIndex].value;
...
}

--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor al baño María: http://www.demogracia.com
--
Nov 3 '08 #5
Bob M wrote:
Fellow php'ers;

I am trying to make a call to a js function from within a php function based
on the selected value of an HTML select statement (whew!).
Can I suggest Xajax (http://xajaxproject.org/)? You'll never have to
think about these things again.
Nov 3 '08 #6
Hugh Oxford wrote:
Bob M wrote:
>Fellow php'ers;

I am trying to make a call to a js function from within a php function
based
on the selected value of an HTML select statement (whew!).
Can I suggest Xajax (http://xajaxproject.org/)? You'll never have to
think about these things again.
It won't help in this case. His problem is not the Ajax call, but how
he was expecting the PHP code to run.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Nov 4 '08 #7

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

Similar topics

11
by: rgintexas | last post by:
i'm trying to get server side vbscript to execute in firefox: </script> <script type="text/VBScript" src="VBFile.vbs"> </script> is there any way i can use javascript to call the vbs file, or...
3
by: Mel | last post by:
Is there a way of restricting operations such as links, buttons etc. to within the <DIV> only ? Let me clarify the problem a little. I am doing an AJAX like operation inside a DIV. I do a...
4
by: Mr. SweatyFinger | last post by:
OK I don't understand ajax, but my page makes a quick ajax call to another page and returns the results. that works ok. That other page is supposed to set a cookie. That doesn't seem to work....
0
by: angiemc | last post by:
Hi, I have a question about AJAX and ASP.Net controls. I'm working on a system that requires pages to be generated dynamically based on XML to provide the layout (eg text boxes, dropdowns, save...
10
by: Piotr Nowak | last post by:
Hi, Say i have a server process which listens for some changes in database. When a change occurs i want to refresh my page in browser by notyfinig it. I do not want to refresh my page i.e....
9
by: art | last post by:
Hi, We have some scripts here where we use some AJAX to populate some of the page. Basically the AJAX routine calls a PHP script. That PHP script uses a bunch of ECHO statements to create...
5
by: Simon | last post by:
I heard that we could do that by using AJAX. Could anybody share how to do it? Thanks.
10
by: laredotornado | last post by:
Hi, I'm using PHP 5. I have a function that takes a little while to run, and I don't want the user to have to wait while it does. Is there a way to run this function in the background? ...
6
by: sheldonlg | last post by:
I came across a problem and googling for an answer didn't help. What I want to do is run an AJAX script that sets a hidden variable on the form. I call the AJAX script from a javascript...
8
by: pankaj17 | last post by:
hello, Is it possible to communicate with another domain javascript function using ajax. Suppose i have a iframe and domain is different and in the iframe i have some links. If user clicks on...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.