473,471 Members | 1,964 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

calling variable in onchange function

I am using a javafunction (onclick in select) in which i am calling a
function in php (thats why i send this to both php and javascript
newsgroups).

in the onclick i call the function "Place_Selected" with the value from the
select (naam_keuze.value)

in the function the value becomes the $zoek_id and searches in the database
for the record with the id of $zoek_id

the naam_keuze.value does not give the value to $zoek_id

When i replace naam_keuze.value for a number (15) i works great.

WHAT AM I DOING WRONG?
This is my code

Function Place_Selected($zoek_id)
{
include("data.php");
$link=mysql_connect($db_host, $username, $password) or die("Database
error!");
mysql_select_db($database , $link)or die("Couldn't open $db:
".mysql_error());
$sql=mysql_query("SELECT * FROM specialismen WHERE id='$zoek_id'");

if ($sql)
{
while($blah2 = mysql_fetch_array($sql))
{
$newsid = $blah2['id'];
$sticky = $blah2['naam'];
}
}
return("document.form.achternaam.value='$sticky'") ;
}
<select id=naam_keuze size=1 name=keuze style=visibility:hidden
onchange=".Place_Selected('naam_keuze.value').";do cument.form.voornaam.value
=naam_keuze.value;>
<option value=0>Kies
$options
</select>

Thanks for suggestions

roy
Jul 17 '05 #1
10 7480
On Wed, 14 Apr 2004 22:48:53 +0200, R.G. Vervoort wrote:
I am using a javafunction (onclick in select) in which i am calling a
function in php (thats why i send this to both php and javascript
newsgroups).

in the onclick i call the function "Place_Selected" with the value from the
select (naam_keuze.value)

in the function the value becomes the $zoek_id and searches in the database
for the record with the id of $zoek_id

the naam_keuze.value does not give the value to $zoek_id

When i replace naam_keuze.value for a number (15) i works great.

WHAT AM I DOING WRONG?
This is my code

Function Place_Selected($zoek_id)
{
include("data.php");
$link=mysql_connect($db_host, $username, $password) or die("Database
error!");
mysql_select_db($database , $link)or die("Couldn't open $db:
".mysql_error());
$sql=mysql_query("SELECT * FROM specialismen WHERE id='$zoek_id'");

if ($sql)
{
while($blah2 = mysql_fetch_array($sql))
{
$newsid = $blah2['id'];
$sticky = $blah2['naam'];
}
}
return("document.form.achternaam.value='$sticky'") ;
}
<select id=naam_keuze size=1 name=keuze style=visibility:hidden
onchange=".Place_Selected('naam_keuze.value').";do cument.form.voornaam.value
=naam_keuze.value;>
<option value=0>Kies
$options
</select>

You have to understand that PHP is executed on the server and Javascript
on the client. So it isn't possible to call a PHP-function from Javascript
as you are trying to do.

So what happens if you substitute 'naam_keuze.value' for the number 15 is
that Place_Selected(15) will be executed by PHP on the server. The result
of this function call will be inserted into you HTML and *then* sent to the
browser (the client) where the Javascript code is executed.
Let's say that the result of the query wil be 'Jan Jansen', than the
resulting HTML wil be:
<select id=naam_keuze size=1 name=keuze style=visibility:hidden
onchange=document.form.achternaam.value='Jan Jansen';
document.form.voornaam.value=naam_keuze.value;>

This is why it sort of works if you substitute 'naam_keuze.value' with 15,
but it will never work otherwise, because Place_Selected will be executed
on the server, thus $zoek_id will become 'naam_keuze.value' which will not
be found.

Does this make any sense to you?

Regards,
Henk Burgstra
Jul 17 '05 #2
R.G. Vervoort wrote:
I am using a javafunction (onclick in select) in which i am calling a
function in php (thats why i send this to both php and javascript
newsgroups).

in the onclick i call the function "Place_Selected" with the value from the
select (naam_keuze.value)

in the function the value becomes the $zoek_id and searches in the database
for the record with the id of $zoek_id

the naam_keuze.value does not give the value to $zoek_id

When i replace naam_keuze.value for a number (15) i works great.

WHAT AM I DOING WRONG?
This is my code

Function Place_Selected($zoek_id)
{
include("data.php");
$link=mysql_connect($db_host, $username, $password) or die("Database
error!");
mysql_select_db($database , $link)or die("Couldn't open $db:
".mysql_error());
$sql=mysql_query("SELECT * FROM specialismen WHERE id='$zoek_id'");

if ($sql)
{
while($blah2 = mysql_fetch_array($sql))
{
$newsid = $blah2['id'];
$sticky = $blah2['naam'];
}
}
return("document.form.achternaam.value='$sticky'") ;
}
<select id=naam_keuze size=1 name=keuze style=visibility:hidden
onchange=".Place_Selected('naam_keuze.value').";do cument.form.voornaam.value
=naam_keuze.value;>
<option value=0>Kies
$options
</select>

Thanks for suggestions

roy


I don't see how it could work, even with a numeric value of 15... What
version of PHP are you using?

Here's why I think it shouldn't work...

Javascript is client side - PHP is server side... thus, you attempt to
call Place_Selected (PHP code) in your onChange event - This won't
happen unless you hava a javascript function with that name that submits
the form contents to the server via a FORM POST or GET...

Also... The value for your select box should I believe end up in
$_POST['keuze'] in PHP when the form is submitted...

And... return("document.form.achternaam.value='$sticky'") ;
Again, you've got your knickers in a twist - the return statement will
not return a value into achternaam like I think you expect... I really
think you are misunderstanding how the two technologies fit together...

If you are sure that your test will work when you enter 15 as a test
value - try different numbers to confirm that test works - If it does,
then I think you've not provided the entire code here for me (perhaps
anyone else) to give a full and proper answer/suggestion.

Does any of the above help?
randelld
Jul 17 '05 #3
it works great, as long as the number (15 or ...) is an id in the database.
i just will not accept the "." (dot) in the line

"Reply Via Newsgroup" <re****************@please.com> schreef in bericht
news:J9kfc.121495$Ig.78826@pd7tw2no...
R.G. Vervoort wrote:
I am using a javafunction (onclick in select) in which i am calling a
function in php (thats why i send this to both php and javascript
newsgroups).

in the onclick i call the function "Place_Selected" with the value from the select (naam_keuze.value)

in the function the value becomes the $zoek_id and searches in the database for the record with the id of $zoek_id

the naam_keuze.value does not give the value to $zoek_id

When i replace naam_keuze.value for a number (15) i works great.

WHAT AM I DOING WRONG?
This is my code

Function Place_Selected($zoek_id)
{
include("data.php");
$link=mysql_connect($db_host, $username, $password) or die("Database
error!");
mysql_select_db($database , $link)or die("Couldn't open $db:
".mysql_error());
$sql=mysql_query("SELECT * FROM specialismen WHERE id='$zoek_id'");

if ($sql)
{
while($blah2 = mysql_fetch_array($sql))
{
$newsid = $blah2['id'];
$sticky = $blah2['naam'];
}
}
return("document.form.achternaam.value='$sticky'") ;
}
<select id=naam_keuze size=1 name=keuze style=visibility:hidden
onchange=".Place_Selected('naam_keuze.value').";do cument.form.voornaam.value =naam_keuze.value;>
<option value=0>Kies
$options
</select>

Thanks for suggestions

roy


I don't see how it could work, even with a numeric value of 15... What
version of PHP are you using?

Here's why I think it shouldn't work...

Javascript is client side - PHP is server side... thus, you attempt to
call Place_Selected (PHP code) in your onChange event - This won't
happen unless you hava a javascript function with that name that submits
the form contents to the server via a FORM POST or GET...

Also... The value for your select box should I believe end up in
$_POST['keuze'] in PHP when the form is submitted...

And... return("document.form.achternaam.value='$sticky'") ;
Again, you've got your knickers in a twist - the return statement will
not return a value into achternaam like I think you expect... I really
think you are misunderstanding how the two technologies fit together...

If you are sure that your test will work when you enter 15 as a test
value - try different numbers to confirm that test works - If it does,
then I think you've not provided the entire code here for me (perhaps
anyone else) to give a full and proper answer/suggestion.

Does any of the above help?
randelld

Jul 17 '05 #4
"R.G. Vervoort" <ro**********@royvervoort.nl> wrote in message
news:40*********************@news.xs4all.nl...

WHAT AM I DOING WRONG?


You're programming in the wrong language. Use ASP.NET instead.
Jul 17 '05 #5
Chung Leong scribbled something along the lines of:
"R.G. Vervoort" <ro**********@royvervoort.nl> wrote in message
news:40*********************@news.xs4all.nl...
WHAT AM I DOING WRONG?

You're programming in the wrong language. Use ASP.NET instead.


Bad comment, no twinkie.

--
Alan Plum, WAD/WD, Mushroom Cloud Productions
http://www.mushroom-cloud.com/
Jul 17 '05 #6
> You're programming in the wrong language. Use ASP.NET instead.

No no, he will become bald if he does :-)
Jul 17 '05 #7
Place_Selected('naam_keuze.value')

you have passed the value of a javascript, this can't work, you have to
explicitely write the value or a php variable, because you are in a php
statement (server side, so no javascript value here).

Savut

"R.G. Vervoort" <ro**********@royvervoort.nl> wrote in message
news:40*********************@news.xs4all.nl...
it works great, as long as the number (15 or ...) is an id in the
database.
i just will not accept the "." (dot) in the line

"Reply Via Newsgroup" <re****************@please.com> schreef in bericht
news:J9kfc.121495$Ig.78826@pd7tw2no...
R.G. Vervoort wrote:
> I am using a javafunction (onclick in select) in which i am calling a
> function in php (thats why i send this to both php and javascript
> newsgroups).
>
> in the onclick i call the function "Place_Selected" with the value from the > select (naam_keuze.value)
>
> in the function the value becomes the $zoek_id and searches in the database > for the record with the id of $zoek_id
>
> the naam_keuze.value does not give the value to $zoek_id
>
> When i replace naam_keuze.value for a number (15) i works great.
>
> WHAT AM I DOING WRONG?
>
>
> This is my code
>
>
>
> Function Place_Selected($zoek_id)
> {
> include("data.php");
> $link=mysql_connect($db_host, $username, $password) or die("Database
> error!");
> mysql_select_db($database , $link)or die("Couldn't open $db:
> ".mysql_error());
> $sql=mysql_query("SELECT * FROM specialismen WHERE id='$zoek_id'");
>
> if ($sql)
> {
> while($blah2 = mysql_fetch_array($sql))
> {
> $newsid = $blah2['id'];
> $sticky = $blah2['naam'];
> }
> }
> return("document.form.achternaam.value='$sticky'") ;
> }
>
>
> <select id=naam_keuze size=1 name=keuze style=visibility:hidden
> onchange=".Place_Selected('naam_keuze.value').";do cument.form.voornaam.value > =naam_keuze.value;>
> <option value=0>Kies
> $options
> </select>
>
> Thanks for suggestions
>
> roy
>
>


I don't see how it could work, even with a numeric value of 15... What
version of PHP are you using?

Here's why I think it shouldn't work...

Javascript is client side - PHP is server side... thus, you attempt to
call Place_Selected (PHP code) in your onChange event - This won't
happen unless you hava a javascript function with that name that submits
the form contents to the server via a FORM POST or GET...

Also... The value for your select box should I believe end up in
$_POST['keuze'] in PHP when the form is submitted...

And... return("document.form.achternaam.value='$sticky'") ;
Again, you've got your knickers in a twist - the return statement will
not return a value into achternaam like I think you expect... I really
think you are misunderstanding how the two technologies fit together...

If you are sure that your test will work when you enter 15 as a test
value - try different numbers to confirm that test works - If it does,
then I think you've not provided the entire code here for me (perhaps
anyone else) to give a full and proper answer/suggestion.

Does any of the above help?
randelld



Jul 17 '05 #8

"Hello World" <he********@500mghosting.com> wrote in message
news:35**************************@posting.google.c om...
You're programming in the wrong language. Use ASP.NET instead.


No no, he will become bald if he does :-)


I'm serious. In ASP.NET the distinction between client and server is
blurred. You can attach an onclick handler to a dropdown on the server side,
and the handler would get called (on the server side) when the user makes a
selection.
Jul 17 '05 #9
ok

I can see that it is a problem (for me)

but....

I can call a php function (with the ". ...... .") in the onchange (wich is
javascript as i believe), is it not possible to call the javascript into a
php function or to decalare a variable and the call it in the function
(since it is possible to put a variable in the function wich works).

thanks anyway

Roy

"Savut" <we***@hotmail.com> schreef in bericht
news:Gj*********************@news20.bellglobal.com ...
Place_Selected('naam_keuze.value')

you have passed the value of a javascript, this can't work, you have to
explicitely write the value or a php variable, because you are in a php
statement (server side, so no javascript value here).

Savut

"R.G. Vervoort" <ro**********@royvervoort.nl> wrote in message
news:40*********************@news.xs4all.nl...
it works great, as long as the number (15 or ...) is an id in the
database.
i just will not accept the "." (dot) in the line

"Reply Via Newsgroup" <re****************@please.com> schreef in bericht
news:J9kfc.121495$Ig.78826@pd7tw2no...
R.G. Vervoort wrote:

> I am using a javafunction (onclick in select) in which i am calling a
> function in php (thats why i send this to both php and javascript
> newsgroups).
>
> in the onclick i call the function "Place_Selected" with the value from
the
> select (naam_keuze.value)
>
> in the function the value becomes the $zoek_id and searches in the

database
> for the record with the id of $zoek_id
>
> the naam_keuze.value does not give the value to $zoek_id
>
> When i replace naam_keuze.value for a number (15) i works great.
>
> WHAT AM I DOING WRONG?
>
>
> This is my code
>
>
>
> Function Place_Selected($zoek_id)
> {
> include("data.php");
> $link=mysql_connect($db_host, $username, $password) or die("Database
> error!");
> mysql_select_db($database , $link)or die("Couldn't open $db:
> ".mysql_error());
> $sql=mysql_query("SELECT * FROM specialismen WHERE id='$zoek_id'");
>
> if ($sql)
> {
> while($blah2 = mysql_fetch_array($sql))
> {
> $newsid = $blah2['id'];
> $sticky = $blah2['naam'];
> }
> }
> return("document.form.achternaam.value='$sticky'") ;
> }
>
>
> <select id=naam_keuze size=1 name=keuze style=visibility:hidden
>

onchange=".Place_Selected('naam_keuze.value').";do cument.form.voornaam.value > =naam_keuze.value;>
> <option value=0>Kies
> $options
> </select>
>
> Thanks for suggestions
>
> roy
>
>

I don't see how it could work, even with a numeric value of 15... What
version of PHP are you using?

Here's why I think it shouldn't work...

Javascript is client side - PHP is server side... thus, you attempt to
call Place_Selected (PHP code) in your onChange event - This won't
happen unless you hava a javascript function with that name that submits the form contents to the server via a FORM POST or GET...

Also... The value for your select box should I believe end up in
$_POST['keuze'] in PHP when the form is submitted...

And... return("document.form.achternaam.value='$sticky'") ;
Again, you've got your knickers in a twist - the return statement will
not return a value into achternaam like I think you expect... I really
think you are misunderstanding how the two technologies fit together...

If you are sure that your test will work when you enter 15 as a test
value - try different numbers to confirm that test works - If it does,
then I think you've not provided the entire code here for me (perhaps
anyone else) to give a full and proper answer/suggestion.

Does any of the above help?
randelld


Jul 17 '05 #10
R.G. Vervoort wrote:
ok

I can see that it is a problem (for me)

but....

I can call a php function (with the ". ...... .") in the onchange (wich is
javascript as i believe), is it not possible to call the javascript into a
php function or to decalare a variable and the call it in the function
(since it is possible to put a variable in the function wich works).

thanks anyway

Roy


LET US GET THIS STRAIGHT (and I'm sorry I'm shouting here) BUT YOU
CANNOT UNDER NO CIRCUMSTANCES CALL PHP CODE USING AN ONCHANGE EVENT
USING THE CODE YOU HAVE IN YOUR ORIGINAL POST (I've copied a line of the
offending code below).

<select id=naam_keuze size=1 name=keuze style=visibility:hidden
onchange=".Place_Selected('naam_keuze.value').";do cument.form.voornaam.value
=naam_keuze.value;>
<option value=0>Kies
$options
</select>

The code contained in the onChange event is expected to be javascript -
NOT PHP.

I'll say that again...

The code contained in the onChange event is expected to be javascript -
NOT PHP.
Your web browser does not process PHP - It can use form methods GET and
POST to communicate with a server, true, but the methods you have used
above WILL NOT WORK.

I'm not saying MIGHT - I'm not saying MAYBE - I'm not saying its a grey
area... I AM DEFINITE, I HAVE NO DOUBT.... PHP is server side - an
onChange event only has access to client side actions. The only link
between the two is a POST or a GET method and from the code I see in
your original post, I don't see this occuring.

Unless you make your code available, either here in a post or via a url,
folk are unlikely to be able to help you. You are wasteing your time.

You mention that some numeric input works for you and I say that is
rubbish... thrash... garbage. If you are adamant that it does work then
you are either mistaken, have a bug in your code and getting the result
from something other than PHP or you have not provided enough of source
code for anyone here to help to show how the data is being sent from
your client, to the server, and back, to give you this result you claim.

I honestly don't mean to offend, but while you persisted in making a
false claim and I needed to clear it up... I'll honestly do my best to
help though...

regards
randelld
Jul 17 '05 #11

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

Similar topics

2
by: calfdog | last post by:
Hello, Does anyone know a workaround for calling fireEvent. With the latest from Microsoft OS XP2 and Hot fixes to IE it now gives an "access denied" error in Python when called. Here is what...
5
by: R.G. Vervoort | last post by:
I am using a javafunction (onclick in select) in which i am calling a function in php (thats why i send this to both php and javascript newsgroups). in the onclick i call the function...
2
by: R.G. Vervoort | last post by:
is it possible to declare a variable in the onchange event of a <select> and use it later in php I would like to put the value of the selected option (in <select>) in a variable and later when i...
8
by: xxgeorge | last post by:
hi all, I'm writing a function that, say, loop through input fields in a form and set default values to it. Some fields are dependent thus I have some onChange scripts to kick off...
11
by: JS | last post by:
I have made a function createFirstMenu where I call "resetMenu" in a JavaScript. But nothing happens when I call resetMenu. function createFirstMenu(sel){ sel = document.getElementById('sel1');...
4
by: Zeebra3 | last post by:
Here goes: I have a web form with several asp:dropdownlists, with which, when selection is changed I want to fire an event defined in some clientside js. The content of the clientside code is...
13
by: monomaniac21 | last post by:
hi i want to be able to trigger a javascript style popup alert in php (i want a message displayed on the actual page) is this possible?
9
by: unlikeablePorpoise | last post by:
I would like to have an HTML dropdown list where each selection calls a method. The following code doesn't work, but it I hope it gives the idea of what I'm trying to do: <FORM NAME="frm">...
22
by: DL | last post by:
Hi, What I wanted to do is to call a function from a newly created element. But it stumbled me. Here's the line that references the newly created element and I used the alert function for...
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
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,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.