2 Replies - 518 Views - Last Post: 07 October 2012 - 04:38 PM Rate Topic: -----

#1 laytonsdad  Icon User is online

  • Cheese and Sprinkles
  • member icon

Reputation: 440
  • View blog
  • Posts: 1,867
  • Joined: 30-April 10

Would you choose PHP or JavaScript to populate form data?

Posted 07 October 2012 - 03:49 PM

So I was planing to create a new back button for my error page after my registration but I began to wonder what method would be best for this. When the user goes back to repair an error, like a miss spelling, the form will be empty. Because I use the Javascript history back, Which will be changed to go to the registration page and populate the form with the data that was send via post prior to the error.

Now my question:
Is it faster (for user experience) to populate the form with PHP prior to sending it to the client or populate it after the document is loaded?

Is This A Good Question/Topic? 0
  • +

Replies To: Would you choose PHP or JavaScript to populate form data?

#2 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3719
  • View blog
  • Posts: 5,991
  • Joined: 08-June 10

Re: Would you choose PHP or JavaScript to populate form data?

Posted 07 October 2012 - 04:10 PM

If you don't have PHP populate the form, it will be returned faster. However, even though that lets the user see the form faster, it still needs to be populated by Javascript, which will undoubtedly take more time than if you had just let PHP populate it in the first place.

The question is: Will seeing the form a handful of milliseconds faster give the user the sense that the page is loading faster, even though the form will be empty until Javascript manages to populate it a few hundred milliseconds later?

I'd guess not. If it were a matter of seconds, perhaps, but not when the time span is so small. - If PHP already has the data when it creates the form HTML, I would have PHP inject it into the form right away.
Was This Post Helpful? 1
  • +
  • -

#3 laytonsdad  Icon User is online

  • Cheese and Sprinkles
  • member icon

Reputation: 440
  • View blog
  • Posts: 1,867
  • Joined: 30-April 10

Re: Would you choose PHP or JavaScript to populate form data?

Posted 07 October 2012 - 04:38 PM

That is what I thought atli. Thank you for the post I was more curious if it was worth doing in Javascript because I am trying to learn to use jquery better.
As you said, if PHP already has the data it my as well do the work. Faster to build also.
Again thank you for your thoughts.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1