There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
access audio avg avg 8 bios blue screen boot bsod computer connection cpu crash css dell desktop dma driver drivers dvd email error excel explorer firefox firefox 3 freeze gimp graphics hard drive hardware hijackthis hjt install internet internet explorer itunes keyboard laptop macro malware monitor motherboard network networking outlook outlook 2003 outlook 2007 outlook express pio problem problems router seo server slow sound sp3 spyware trojan usb video virtumonde virus vista vundo windows windows vista windows xp winxp wireless
Web Design & Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Internet & Networking > Web Design & Development >
HTML Web Forms AND Repopulating the form


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

 
Thread Tools
ajaytemp's Avatar
Computer Specs
Junior Member with 19 posts.
 
Join Date: Jun 2007
Location: Columbus, OH
Experience: Sharp w/ computers.
20-Jun-2008, 09:12 AM #1
Question HTML Web Forms AND Repopulating the form
I have a web form with a simple name input. And a submit button.
Then the action takes one back to the same webpage.
How do I repopulate the name into that webpage?

Thx,
Ajay
Mr.LLB's Avatar
Senior Member with 138 posts.
 
Join Date: May 2008
20-Jun-2008, 10:44 AM #2
i am not sure what you'r trying to ask.....do you want to put the name back into the textbox once it has submited?
ajaytemp's Avatar
Computer Specs
Junior Member with 19 posts.
 
Join Date: Jun 2007
Location: Columbus, OH
Experience: Sharp w/ computers.
20-Jun-2008, 11:18 AM #3
Yes
Quote:
Originally Posted by Mr.LLB View Post
i am not sure what you'r trying to ask.....do you want to put the name back into the textbox once it has submited?
Yes.
tomdkat's Avatar
Computer Specs
Distinguished Member with 3,521 posts.
 
Join Date: May 2006
Location: S.F. Bay Area, CA
Experience: Intermediate
20-Jun-2008, 12:08 PM #4
If the page that is displayed has the fields entered on the form as part of the URL, you can use JavaScript to fill-in the form with the values the user entered when the form is re-displayed.

So, let's say the form is at this address:

www.mysite.com/form.html

The user fills out the form and submits it and this URL is then loaded:

www.mysite.com/form.html?name=tomdkat

If that is how the URL looks after they submit the form, you can use JavaScript to parse out the name and put it in the appropriate field on the form when it's displayed.

Peace...
ajaytemp's Avatar
Computer Specs
Junior Member with 19 posts.
 
Join Date: Jun 2007
Location: Columbus, OH
Experience: Sharp w/ computers.
20-Jun-2008, 12:11 PM #5
How?
Ok, there are bunch of links on the web to parse using JavaScript.
But is there an easier way b/c I don't remember the instructor doing this in class.

THX,
Ajay

Quote:
If the page that is displayed has the fields entered on the form as part of the URL, you can use JavaScript to fill-in the form with the values the user entered when the form is re-displayed.

So, let's say the form is at this address:

www.mysite.com/form.html

The user fills out the form and submits it and this URL is then loaded:

www.mysite.com/form.html?name=tomdkat

If that is how the URL looks after they submit the form, you can use JavaScript to parse out the name and put it in the appropriate field on the form when it's displayed.

Peace...

Last edited by ajaytemp : 20-Jun-2008 12:22 PM.
tomdkat's Avatar
Computer Specs
Distinguished Member with 3,521 posts.
 
Join Date: May 2006
Location: S.F. Bay Area, CA
Experience: Intermediate
20-Jun-2008, 12:22 PM #6
Quote:
Originally Posted by ajaytemp View Post
How would I do this in JavaScript?
Carefully.

Here is some JavaScript that should do what you want.

Quote:
And is there an easier way?
Unless your form is being dynamically generated by a server-side script, something will have to fill in the appropriate fields since the browser won't do it on its own. Using JavaScript is just one solution and I don't think it's complicated or difficult.

Peace...
tomdkat's Avatar
Computer Specs
Distinguished Member with 3,521 posts.
 
Join Date: May 2006
Location: S.F. Bay Area, CA
Experience: Intermediate
20-Jun-2008, 12:23 PM #7
Quote:
Originally Posted by ajaytemp View Post
But is there an easier way b/c I don't remember the instructor doing this in class.
Ok, then ask your instructor what method they used.

Peace...
ajaytemp's Avatar
Computer Specs
Junior Member with 19 posts.
 
Join Date: Jun 2007
Location: Columbus, OH
Experience: Sharp w/ computers.
20-Jun-2008, 12:27 PM #8
after you press submit
"If that is how the URL looks after they submit the form, you can use JavaScript to parse out the name and put it in the appropriate field on the form when it's displayed."

"...and put it in the appropriate field on the form when it's displayed."


I understand the JavaScript parsing part. But getting those fields displayed on the form again, i do not.

This is a self-learn course. Instructor won't help!
TheRobatron's Avatar
Computer Specs
Senior Member with 417 posts.
 
Join Date: Oct 2007
Location: England
Experience: Intermediate
20-Jun-2008, 12:27 PM #9
You can achieve this with a server side language, which is more reliable than Javascript (though Javascript may be preferable in some circumstances). Using Tomdkat's URL example, this is the code you could use:
PHP Code:
$name $_REQUEST['name'];
if (isset(
$name)) {
echo 
"<input type='text' name='name' value='$name' />";

tomdkat's Avatar
Computer Specs
Distinguished Member with 3,521 posts.
 
Join Date: May 2006
Location: S.F. Bay Area, CA
Experience: Intermediate
20-Jun-2008, 12:35 PM #10
Quote:
Originally Posted by ajaytemp View Post
I understand the JavaScript parsing part. But getting those fields displayed on the form again, i do not.
Once you have the appropriate field parsed on, you set the element's value to make the field display.

So, if the input field looks like this:

Code:
<input name="fname" type="text" length="20" id="fname"/>
Then you can access that in the JavaScript code like this:
Code:
formField = document.getElementById('fname');
formField.value={var with name parsed with JavaScript};
Peace...
tomdkat's Avatar
Computer Specs
Distinguished Member with 3,521 posts.
 
Join Date: May 2006
Location: S.F. Bay Area, CA
Experience: Intermediate
20-Jun-2008, 12:36 PM #11
Quote:
Originally Posted by TheRobatron View Post
You can achieve this with a server side language, which is more reliable than Javascript (though Javascript may be preferable in some circumstances).
More reliable? How so?

Peace...
TheRobatron's Avatar
Computer Specs
Senior Member with 417 posts.
 
Join Date: Oct 2007
Location: England
Experience: Intermediate
20-Jun-2008, 12:38 PM #12
It will work in browsers that don't support Javascript. (I know most browsers do, but I think it's best to do things that will work for everyone )
tomdkat's Avatar
Computer Specs
Distinguished Member with 3,521 posts.
 
Join Date: May 2006
Location: S.F. Bay Area, CA
Experience: Intermediate
20-Jun-2008, 12:42 PM #13
That's true. The flip-side of that is the site will have to be hosted on a server that supports PHP and that might not be a guarantee either. However, you do raise an interesting point about JavaScript. Would a JavaScript blocking browser add-on prevent JavaScript parsing of a HTML form? I disable certain JavaScript functions in browsers I use but those don't impact JavaScript functions this nature.

Also, a "noscript" tag could be added stating JavaScript is required for the form to function so that the user is informed of that before filling out the form.

Great point, TheRobatron!

Peace...
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are Off
Refbacks are Off

You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 03:47 PM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.