IOWA select

M

Mark Probert

Kirk,

What is the correct way of getting the selected value from a select list?
I am doing the following (not working)

<form oid="submit">
<label><b>Select Filelist</b></label>
<select oid="userList" name="selected">
<option>@ufile</option>
</select>
<p></p>
<input type="submit" oid="display" value="Display"/>
<input type="submit" oid="cancel" value="Cancel"/>
</form>
 
D

David Naseby

-----Original Message-----
From: Mark Probert [mailto:p[email protected]]
Kirk,

What is the correct way of getting the selected value from a select list?
I am doing the following (not working)

<form oid="submit">
<label><b>Select Filelist</b></label>
<select oid="userList" name="selected">
<option>@ufile</option>
</select>
<p></p>
<input type="submit" oid="display" value="Display"/>
<input type="submit" oid="cancel" value="Cancel"/>
</form>

IANK, but try

<select oid="userList">
<option oid="ufile">
</select>

<?
userList {
item = ufile
list = create_user_list
}
?>

David
http://homepages.ihug.com.au/~naseby/
 
M

Mark Probert

David Naseby said:
IANK, but try

<select oid="userList">
<option oid="ufile">
</select>

<?
userList {
item = ufile
list = create_user_list
}
?>

Yup. Just about to post as well.

Thanks, David.
 
K

Kirk Haines

IANK, but try

<select oid="userList">
<option oid="ufile">
</select>

<?
userList {
item = ufile
list = create_user_list
}
?>

Yup. Just about to post as well.

Thanks, David.[/QUOTE]

David got it. Think of it this way:

A select list is a two part widget. You have the select box, which requires
a repeated list of options, and then you have each of the options.

If you do your first form:

<select oid="userList">
<option>@ufile</option>
</select>

Then the list will look right, but Iowa won't know which object was actually
selected in the select box. Now, on the surface that seems confusing, but
consider this. What if ufile were, instead of a string, a struct or some
other object that had, say, a name() method/reader. So you could do this:

<select oid="userList">
<option>@ufile.name</option>
</select>

You will see the names in the select box, but Iowa has no way of equating
those names with the object they came from. However, if you do this:

<select oid="userList">
<option oid="ufile.name"/>
</select>

Then Iowa can say, "By Jove! That <option> tag is dynamic! When it is
selected, I need to return whatever @ufile was for that tag."

I use this all of the time in instances where I have performed a database
query, putting the rows into an array of objects. From the user
perspective, they are simply going to select one or more options from a
select box, but at the code level, they are really selecting rows with all
of the data items that go with them.

Chemical Name: <select oid="chemical_list">
<option oid="chemical.chemical_name"/>
</select>

When the code gets the selection, it gets the full object, not just the
name. Because of this (this example assumes Kansas object/relational
mapping syntax), if I want to actually get a list of all of the schools that
have that chemical for a new page where they are going to select a school,
all I have to do is:

@school_list = @chemical.schools

And that is very, very nice.

Make sense?


Thanks for the question,

Kirk
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,156
Messages
2,570,878
Members
47,408
Latest member
AlenaRay88

Latest Threads

Top