views:

2531

answers:

2

Hello, does anyone know if it's possible to pass HTML vlaues in with a form page?

So for example if the user selected foo from a list of say 10 options, I would want to pass a hidden value in and retrieve that as a request parameter, e.g. so I could then retrieve the values "foo" and "bar" from the request.
Thanks Andrew

A: 

There is the form input type='hidden' which you could update using the onchange event of the select drop down then it would be posted with the form. I suspect you would want to create an array of the possible values for the hidden input in the same order as their equivalents in the select drop down and then access the value in the array by index using the selectedIndex property of the select element.

Dave Anderson
Thanks Dave, I considered Javascript but decided against it in the end. I want to use a purely HTML solution.
A: 

A select list has both a value that is displayed to the user and a value that is passed back to the server in the form post. So you could use some sort of delimiter in the posted value to get both values sent back and then parse them at that point:

        <select id="myselectlist" >
            <option value="foo|bar">foo</option>
            <option value="foo2|bar2">foo2</option>
        </select>

But better yet would be to pass back an ID value which you could then use to know which item was selected from a database and also use it to look up the second related item:

        <select id="myselectlist" >
            <option value="123">foo</option>
            <option value="124">foo2</option>
        </select>

Your database might look like this:

ID   DisplayValue   OtherData   
123  foo            bar     
124  foo2           bar2
Jeff Widmer
Thanks for that. I am actually using the parsing method at the moment but wondered if there was a slightly nicer way by posting back two values with the selection. I can't use the ID value solution because the second value isn't stored in the database. By the way my HTML code that I included in my question didn't get displayed, probably because I didn't format it correctly, so that's why it reads badly, sorry!
try storing otherdata to the option id
Fleents