|
Posted by Malcolm Dew-Jones on 09/06/05 02:47
David (martindb@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.
[Back to original message]
|