![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
|
I am on the 'edit' screen of a web form, and I have a bunch of variables coming from a database that need to be placed into the form. In the past, I have been using PHP to pre-populate each field, something like input type="text" id="firstName" value="<?= $first_name ?>" / But, since my "add" and "edit" screens are virtually the same, I'm thinking about using PHP to dynamically create "onload" javascript events that use a custom function... essentially something along the lines of onload = "setForm('firstName','<?= $first_name ?>');" So, option one hard-codes the form-field value directly into the HTML. Option two uses javascript to populate the fields. |
|
This is a specific web application targeted to a finite audience who will be using javascript-enabled browsers. At this point, I'm thinking of going with the second option(javascript based), because I won't have to scroll down to each form-field tag in my document and add the "value" parameter (read: time saver).... the only drawback I can see is CPU Power I guess... Or is that a ridiculous concern? What about using Javascript to populate 100 fields? |
|
Most importantly, do I need to worry about client-side interruptions that can prevent the form from being populated (other than turning javascript off)? |
#2
| |||
| |||
|
|
The only point would be saving me programming time. On a page with 50+ form-fields, I can save lot of time by writing a PHP loop that writes an HTML call to a javscript function instead of going to each form field and entering the value="<?= $first_name ?>" stuff... May I suggest learning templates? They exist for just this sort of thing. They take the edge off writing repetative pages. Either write your own templating toolkit (better) or get one off the shelf. |
#3
| |||
| |||
|
|
"d" <d (AT) example (DOT) com> wrote in news:zm_Nf.29523$wl.21033 (AT) text (DOT) news.blueyonder.co.uk: The only point would be saving me programming time. On a page with 50+ form-fields, I can save lot of time by writing a PHP loop that writes an HTML call to a javscript function instead of going to each form field and entering the value="<?= $first_name ?>" stuff... May I suggest learning templates? They exist for just this sort of thing. They take the edge off writing repetative pages. Either write your own templating toolkit (better) or get one off the shelf. is this where the SMARTY thing comes into play? I've heard of it for a long time but have never used it, as I generally prefer to code my applications personally... |
It's not as hard as you'd imagine.
|
i think i'm still looking for a good reason NOT to use javascript to populate my form fields, since I know that my audience is finite and restricted to javascript-enabled browsers.... especially when my form has 50+ fields. it's too late to look at templating (ie: learning something new) at this point in the project, but i will do it in the future. |
just be aware that any errors in javascript
|
thanks |
![]() |
| Thread Tools | |
| Display Modes | |
| |