Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

javascript forms question

5:08 pm on Mar 12, 2002 (gmt 0)

Junior Member

10+ Year Member

joined:Sept 12, 2001
votes: 0

I am populating a hidden field on a form with the following code:

onChange="if (this.selectedIndex >-1) {
var t='';
for (var i=this.selectedIndex;i<this.options.length;i++) {
if (this.options[i].selected) t += this.options[i].value + '\,';
this.form.country.value = t;
}" multiple>
<option value="UK">one
<option value="Germany">two
<option value="USA">three
<option value="Other">four
<input type="hidden" name="country" value="">

This adds the value selected and separates each one in the hidden field with a comma.

This form resides in a members area on my site and makes up part of a registration form and is outputted by a perl script. The data submitted is added to a flat file database.

The problem I have is reading back the data when someone wants to update their details.
The modify details page is essentially the same as the register page but with the fields pre-populated with data selected on registration.

How can I modify the code above so on load it reads back the data and populates the multiple select box with values from the hidden field, but at the same time update the hidden field if the user changes their selection.

I can call the data stored in the hidden field with a variable such as $data[3]

I am learning scripting at the moment and regard myself as a novice so and help would be gratefully appreciated.

8:38 pm on Mar 12, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member tedster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:May 26, 2000
votes: 0

>> The problem I have is reading back the data when someone wants to update their details.

I'm not clear whether this is a CGI/Perl problem for you or a Javascript problem. Do you need to pre-populate the form by "reading back" information already in the flat file?

If so, you may need some of the expertise that hangs around our server-side scripting forum.


Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members