473,320 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Getting values into a form: PHP (Server) or Javascript (Client) Side?

Hi

This is sort of a weird question, perhaps a bit off-topic...

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)?

Thoughts appreciated!
Mar 3 '06 #1
4 2338
Good Man wrote:
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.
Hardcode would be to use

<input type="text" id="firstName" value="John" />

directly in the page.

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?
You just moved the process time from the server to the client, what can slow
things down is the size of the javascript, the more the more lagish the page
will be.

Most importantly, do I need to worry about client-side interruptions that
can prevent the form from being populated (other than turning javascript
off)?


I don't really see the point in using javascript at all in this case, you get
a more difficulty to figure out bugs.

if you use

<input type="text" id="firstName" value="<?= $first_name ?>" />
<input type="text" id="secondtName" value="<?= $second_name ?>" />
<input type="text" id="lastName" value="<?= $last_name ?>" />

You either have a value set of the variables $first_name, $second_name,
$last_name and so on (I know, I added the two last ones).

If a value isn't set, then the box will be empty and it's just to add the
values manually.
//Aho
Mar 3 '06 #2
"J.O. Aho" <us**@example.net> wrote in
news:46************@individual.net:

I don't really see the point in using javascript at all in this case,
you get a more difficulty to figure out bugs.

if you use

<input type="text" id="firstName" value="<?= $first_name ?>" />
<input type="text" id="secondtName" value="<?= $second_name ?>" />
<input type="text" id="lastName" value="<?= $last_name ?>" />

You either have a value set of the variables $first_name,
$second_name, $last_name and so on (I know, I added the two last
ones).

If a value isn't set, then the box will be empty and it's just to add
the values manually.


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...
Mar 3 '06 #3
"d" <d@example.com> wrote in
news:zm******************@text.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...

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.
thanks
Mar 3 '06 #4
d
"Good Man" <he***@letsgo.com> wrote in message
news:Xn************************@216.196.97.131...
"d" <d@example.com> wrote in
news:zm******************@text.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...


then write your own template toolkit :) It's not as hard as you'd imagine.
Mine is well under 200 lines, and that's got a lot of comments and
white-space. I prefer to write my own code as well ;)
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.
Of course - if you think it'll work, and if you're happy that your audience
can run it, then go for it :) just be aware that any errors in javascript
on the page will most likely result in the fields not being populated, and a
wee bit more processing power is required for each page (but nothing
drastic - barely noticeable).

use the javascript, and learn templating when you get a chance :)

thanks


cheers!

dave
Mar 3 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: TG | last post by:
Dear PHP Group, I have two forms that are used to collect user information. The first one takes user inputted values such as fullname, city, address etc. I want these values to display in the...
9
by: Ken | last post by:
How can I reset the initial form variables that are set with session statements when clicking on a button? I tried this but the function was not called: <?PHP function reset_form($none) {...
5
by: Danny | last post by:
Does anybody have a nice method of forcing a user to enter a value into a form using asp? I think the best is to have a popup when they hit submit that will stay on the same page and then just...
5
by: Noorul Ameen | last post by:
Dear Folks, In a HTML page I want to get all the files in a selected dirs. Is that any way to do this thru javascript. Help will be highly appreciated. Thanks in advance. Regards, Ameen T
2
by: Alex | last post by:
Hi all, I'm writing a small web application which searches a database based on a date field, and populates a datagrid control with the results. The datagrid control has selection buttons added...
6
by: Janaka | last post by:
Help! I have two ListBox controls on my web form. The first one gets populated on entry with values from the DB. I then use JavaScript to copy options from this ListBox to my second one. (I...
3
by: awebguynow | last post by:
in other words, Can I make client side mod's before I submit a form and Post ? I guess its just a matter of cycling through the form elements and setting value to null (or empty string) for...
9
by: Good Man | last post by:
Hi This is sort of a weird question, perhaps a bit off-topic... 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...
5
by: sklett | last post by:
I'm not real experienced with asp.net so this may be obvious. I've got a situation where some of my client side javascript is causing my posted form's controls to lose their values. In other...
9
Catalyst159
by: Catalyst159 | last post by:
I have a form which is used to calculate residential Floor Area Ratio (FAR). The form is structured into seven parts as follows: Part A: Maximum FAR and Floor Area: Part B: Gross Floor Area of...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.