472,102 Members | 2,080 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,102 software developers and data experts.

Can PHP control a form value directly

Ok. Can PHP control a form value directly? Eg. like the javascript
"document.Form1.text01.value = "Y"". Eg. allow me to put a value into
a form text field on page load. Either I missed this in my PHP book
or the function does not exist.

The only way I have seen is to put code in the value part of the input
item, see below.

Thanks

<input type="text" value = "<? echo sprintf("%01.2f",
$TotalCost);?>"/>
Sep 5 '05 #1
6 2408
David said the following on 05/09/2005 23:06:
Ok. Can PHP control a form value directly? Eg. like the javascript
"document.Form1.text01.value = "Y"". Eg. allow me to put a value into
a form text field on page load. Either I missed this in my PHP book
or the function does not exist.
PHP is server-side, so it has no control of the form, other than the
HTML/Javascript/etc. that is sent to the browser.

The only way I have seen is to put code in the value part of the input
item, see below.
<input type="text" value = "<? echo sprintf("%01.2f",
$TotalCost);?>"/>


So this (and variants) are the only way of doing this.

--
Oli
Sep 5 '05 #2
David (ma******@sbcglobal.net) wrote:
: Ok. Can PHP control a form value directly? Eg. like the javascript
: "document.Form1.text01.value = "Y"". Eg. allow me to put a value into
: a form text field on page load. Either I missed this in my PHP book
: or the function does not exist.

: The only way I have seen is to put code in the value part of the input
: item, see below.

: Thanks

: <input type="text" value = "<? echo sprintf("%01.2f",
: $TotalCost);?>"/>

Normally php is simply generating text to send to the browser, so yes,
normally the above is exactly what you have to do (give or take the choice
of php commands to use).

If you use a template system to generate your output then there may be a
technique provided by the template system to set a value. In that case
you create and populate your template and then send the template, as a
long text string, to the browser. Whether the template control language
looks similarly to Javascript will depend on the template system.

One special case of a template system is to use something like an xml
builder library. Your php program can build an xml data structure in
memory. That DOM can be manipulated all you like. When it is ready you
send a stringified version of the DOM to the brower.

In no case, however, you are ever manipulating the value on the browser
like javascript would. All you can ever do is prepare a finished version
of the html text (including what ever values you wish) and then you send
that finished text to the browser.

Well actually, if you run a Java applet on the browser then the server may
have the ability to communicate directly with the values being displayed,
but that is a whole other kettle of coffee, and I have no idea what (if
any) php libraries would help you do that. (Not to mention that you would
probably need to write your own custom Java applet as well). I mention
this just for completeness, it is not something most web programmers will
ever do.

--

This programmer available for rent.
Sep 5 '05 #3
No.

That being said you could always remote with Flash or Processing or a
POJA.

Sep 6 '05 #4
Thanks for the info. I guess I have been having too much fun with
ASP.net, which allows direct asp forms access.

Need to shift back to the php mindset!
On Mon, 05 Sep 2005 22:45:53 GMT, Oli Filth <ca***@olifilth.co.uk>
wrote:
David said the following on 05/09/2005 23:06:
Ok. Can PHP control a form value directly? Eg. like the javascript
"document.Form1.text01.value = "Y"". Eg. allow me to put a value into
a form text field on page load. Either I missed this in my PHP book
or the function does not exist.


Sep 8 '05 #5
I noticed that Message-ID: <j6********************************@4ax.com>
from David contained the following:
Thanks for the info. I guess I have been having too much fun with
ASP.net, which allows direct asp forms access.


Yebbut, it uses Javascript to do it!

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Sep 8 '05 #6
Geoff Berrow <bl******@ckdog.co.uk> wrote:
I noticed that Message-ID: <j6********************************@4ax.com>
from David contained the following:
Thanks for the info. I guess I have been having too much fun with
ASP.net, which allows direct asp forms access.


Yebbut, it uses Javascript to do it!


Exactly. I've sometimes wondered how many ASP.NET programmers realize that
their simple forms code is generating hordes of Javascript, and that many
seemingly simple user interface actions require rather expensive round
trips.
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Sep 10 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by John Lau | last post: by
9 posts views Thread by TCORDON | last post: by
6 posts views Thread by evandelagrammaticas | last post: by
4 posts views Thread by =?Utf-8?B?UmljaEI=?= | last post: by
3 posts views Thread by Allen Chen [MSFT] | last post: by
reply views Thread by leo001 | last post: by

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.