There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
bios black screen blue screen blue screen of death boot computer connection crash css dell display driver drivers email error firefox firefox 3 game hard drive internet internet explorer itunes laptop malware monitor network networking nvidia outlook outlook 2003 outlook express partition password printer problem problems router security slow software sound sprtcmd.exe trojan usb video virus vista windows windows xp 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!

Closed Thread
 
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 144 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,716 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,716 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,716 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 482 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,716 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,716 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 482 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,716 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...
Closed Thread

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who help people like you solve computer problems. See our Welcome Guide to get started.



Thread Tools


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:20 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.