Welcome to WebmasterWorld Guest from 54.161.110.186

Forum Moderators: open

Message Too Old, No Replies

javascript forms question

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

10+ Year Member



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

<select
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
</select>
<br>
<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)

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



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

 

Featured Threads

Hot Threads This Week

Hot Threads This Month