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

Discussion in 'HTML' started by Good Man, Mar 3, 2006.

  1. Good Man

    Good Man Guest

    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!
     
    Good Man, Mar 3, 2006
    #1
    1. Advertising

  2. Good Man

    Good Man Guest

    "J.O. Aho" <> wrote in
    news::


    > 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...
     
    Good Man, Mar 3, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Qw==?=
    Replies:
    1
    Views:
    3,256
    Hermit Dave
    Jan 16, 2004
  2. Shaul Feldman
    Replies:
    0
    Views:
    859
    Shaul Feldman
    Apr 16, 2004
  3. Rajive Narain
    Replies:
    0
    Views:
    1,988
    Rajive Narain
    Sep 18, 2009
  4. Renuka
    Replies:
    1
    Views:
    121
    Michael Winter
    Nov 13, 2003
  5. FAQ server
    Replies:
    22
    Views:
    305
    Garrett Smith
    May 14, 2010
Loading...

Share This Page