TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   fetch data in a form without using post? (http://www.talkphp.com/absolute-beginners/2742-fetch-data-form-without-using-post.html)

kororo203 05-01-2008 01:42 AM

fetch data in a form without using post?
 
let's say that i'll be making functions that should be able to execute in the page while not making use of post method...

like this..

<form>
<input type = "text" name = "text" />
<input type = "button" name = "call" onclick = "<?call();"?>" />
</form>

correct me if i'm wrong but is this possible...

freenity 05-01-2008 01:49 AM

the onclick event is for javascript, not php. So you can't do this.
You can execute the call() function using an ajax call...

kororo203 05-01-2008 01:55 AM

i think that the onclick is an available option for the input type button isn't it?

freenity 05-01-2008 12:01 PM

yes but only for javascript:

input type="text" onclick="[javascriptCode]">


input type="text" onclick="alert('test')">

The above will work because it's executed on the client's machine, but the php code is parsed before the page is send to the client (on the server) so it is impossible to know when the user will click it.
However you can make an ajax call:


input type="text" onclick="$.get('page.php')">

And page.php will have a call to you function: <?call();"?>

This will work. (The above code uses jQuery library)

Village Idiot 05-01-2008 03:04 PM

Javascript is a client side language and can be executed at any time. PHP is a server side language and is done parsing the code when you see the page. Javascript starts after PHP ends. Since they are ran at different times, you can not call PHP from javascript. What you can do is use ajax to send a request to a PHP page and get the response. I have a limited knowledge of javascript, so someone else will have to help you with that.

sarmenhb 05-14-2008 01:37 AM

perhaps if we did this then its possible


Code:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript" type="text/javascript">

function jscall() {

var output = "<?php echo $output = "php passwed to javascript"; ?>";
alert(output);


}
</script>
</head>

<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="submit" name="submit" value="submit" onclick="jscall()" />
</form>
</body>
</html>



All times are GMT. The time now is 12:11 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0