Can I add PHP script onchange Event of Drop down menu?

9,147 views
Skip to first unread message

Madhuri Phaltane

unread,
Feb 2, 2011, 12:16:26 AM2/2/11
to professi...@googlegroups.com
Can I add PHP script onchange Event of Drop down menu?

--
Thanks & Regards,
Madhuri Phaltane.
9325514952

Madhuri Phaltane

unread,
Feb 2, 2011, 12:48:23 AM2/2/11
to professi...@googlegroups.com

I have done like this

<script language="php" >
function check()
{
**********
}

</script>

<body>

<select name="select" onchange="check();">
<option>---select---</option>
<option>1</option>
<option>2</option>
<option>3</option>
</select>
</body>


But its not working....
Can anybody help me to find out ,How to do this???????

Jack Timmons

unread,
Feb 11, 2011, 8:12:36 AM2/11/11
to professi...@googlegroups.com
On Tue, Feb 1, 2011 at 11:48 PM, Madhuri Phaltane
<madhuri...@gmail.com> wrote:
>
> I have done like this
>
> <script language="php" >
> function check()
> {
> **********
> }
>
> </script>
>
> <body>
>
> <select name="select" onchange="check();">
> <option>---select---</option>
> <option>1</option>
> <option>2</option>
> <option>3</option>
> </select>
> </body>
>
>
> But its not working....
> Can anybody help me to find out ,How to do this???????

PHP is a server side script. You can't run it in a client's browser.

You can, however, run an AJAX query to a PHP page and get back data.

--
Jack Timmons
@_Codeacula
Trollfree: 8503290326

rajendra prasad siva

unread,
Feb 28, 2011, 12:18:16 AM2/28/11
to professi...@googlegroups.com, Jack Timmons
Hi all ,
I think we can directly call a php function in javscript;
I used php code directly in js many a times.

eg:

<body>
<select name="select" onchange="<?php check(); ?>">
</body>

<?php
function check(){
-------code-------
}

?>


--
This group is managed and maintained by the development staff at 360 PSG. An enterprise application development company utilizing open-source technologies for todays small-to-medium size businesses.

For information or project assistance please visit :
http://www.360psg.com

You received this message because you are subscribed to the Google Groups "Professional PHP Developers" group.
To post to this group, send email to Professi...@googlegroups.com
To unsubscribe from this group, send email to Professional-P...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/Professional-PHP

rajendra prasad siva

unread,
Feb 28, 2011, 2:10:26 AM2/28/11
to professi...@googlegroups.com
Hi ,

I'll give u a clear example and it is working fine for me! forget the first one.



<html>
<head>
<script type="text/javascript">
function check(str){
//document.write(str)
alert(str)
}

</script>
</head>
<body>

<select name="select" onchange="check('<?php phpfun();?>'+this.value)">

<option>---select---</option>
<option>1</option>
<option>2</option>
<option>3</option>
</select>
</body>
</html>

<?php

function phpfun(){
echo 'Selected Value:';
}
?>

Sam Doyle

unread,
Feb 28, 2011, 8:32:45 AM2/28/11
to professi...@googlegroups.com
That is incorrect and will not work!

khan abuzaid

unread,
Feb 28, 2011, 8:44:11 AM2/28/11
to professi...@googlegroups.com
Go with Ajax.
Attachment simple ajax dropdown.
Regards

Khan Abuzaid
Mob# :09664541886
Mumbai
Dropdown.rar

Robert Gonzalez

unread,
Feb 28, 2011, 10:33:42 AM2/28/11
to professi...@googlegroups.com
Javascript = client side.
PHP = Server side.

vishal bhandare

unread,
Mar 7, 2011, 9:19:35 AM3/7/11
to professi...@googlegroups.com, Robert Gonzalez
I think rajendra prasad siva can do it. :)

Jack Timmons

unread,
Mar 7, 2011, 9:34:34 AM3/7/11
to professi...@googlegroups.com
On Mon, Mar 7, 2011 at 8:19 AM, vishal bhandare
<bhandar...@gmail.com> wrote:
> I think rajendra prasad siva can do it. :)

rajendra prasad siva is not running PHP on the client side like the OP
requested.

rajendra prasad siva is writing a PHP function to echo out a string.

So, when he says:
<select name="select" onchange="check('<?php phpfun();?>'+this.value)">

And then below has this function:

function phpfun(){
echo 'Selected Value:';
}

He is basically doing:
<select name="select" onchange="check('<?php echo("Selected
Value");?>'+this.value)">

Which, as we all know, becomes:
<select name="select" onchange="check('Selected Value:'+this.value)">

So, when you run his script, you get this:
http://codeacula.net/really.php

View the source, and you will find absolutely no PHP.

But, Codeacula, that's not fair! Apache parses the PHP and doesn't let
the client give it a shot!

Oh yea?
http://codeacula.net/really.html

Broke, ain't it?

So, what you think, essentially, is wrong, and any of you who continue
debating that you can run PHP in a user's browser simply show only
that your knowledge of both PHP and how the Internet works is
absolutely -wrong-.

Is it possible, with extensions or special browsers, to run PHP on in
the browser, but I don't think something like that has been made yet,
I doubt it would pick up any popularity, and if it has been made it's
likely proprietary.

The OP wants PHP to run in the browser, from what this month old email
has gathered. If you can prove me wrong, do so, and I'll admit fault.
Otherwise, quit showing your ignorance of PHP, Javascript, and the
worldwide web, and let the topic die.

</evildreamsquashinggrognardofFUD>

--
Jack Timmons
@_Codeacula

Reply all
Reply to author
Forward
0 new messages