0

is it possible to use php as a client side scripting language?
if it possible, how can i read values releated with the form?

7
Contributors
6
Replies
7
Views
7 Years
Discussion Span
Last Post by Will Gresham
Featured Replies
  • 1
    diafol 3,317   7 Years Ago

    I came across this a little while ago. I tried some of the functions and they were fine, although one or two didn't work (probably my fault): [url]http://phpjs.org/[/url] It's basically a set of js functions named after php functions. Interesting. Read More

0

This, sir, is exactly what JavaScript was created for.

Here is an example of how to access a form element with the name "input1":

<html>
<body>
<form onSubmit="return getFormValue()">
	<input type="text" name="input1"/><br/>
	<input type="submit" value="Submit"/>
</form>

<script type="text/javascript">
function getFormValue() {
	var myInput = document.getElementsByName("input1");
	if (myInput)
		alert("input1's value: " + myInput[0].value);
	return false;
}
</script>
</body>
</html>

This will alert the value of what's typed into the input element when you click Submit.

1

I came across this a little while ago. I tried some of the functions and they were fine, although one or two didn't work (probably my fault):

http://phpjs.org/

It's basically a set of js functions named after php functions. Interesting.

Votes + Comments
nice.....Thanks for share this
0

To answer the actual question:
No, you can't use PHP client-side.

Unless you happen to have a browser that supports PHP as a scripting language.
(Of which I know none)

I came across this a little while ago. I tried some of the functions and they were fine, although one or two didn't work (probably my fault):

http://phpjs.org/

It's basically a set of js functions named after php functions. Interesting.

Yea, I tried those to a while back. Very useful.

This should make it easier for PHP programmers to get started with JavaScript. They would at least have the basic PHP functions available.

0

If you are trying to get values from a form, why not use the $_POST and $_GET vars in PHP... Any data from the form will be in these.

Using JavaScript is all well and good until you come across a browser which either has JavaScript disabled or does not support JavaScript.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.