On Thursday, November 13, Jeff wrote:

[snip]What I now need to do is store not only the userID but the email
address as well.  Is there a way using a form to store 2 values using
one drop down box?  So basically I want to store the userID and the
Email address to a variable in the form so that both may be written to
different
fields in the database later.[/snip]

Hi Jeff.  For this you'll need to use javascript and hidden form fields.
I've had to do this in a few places in my CMS and it's not too
difficult.

The Javascript will be something like this:

<script type="text/javascript">
<!--
// x is the select list in question
function setEmail(x)
{
        var users = new Array();
        <?php
        $count = 0;
        foreach ($users as $id=>$user)
        {
                echo 'users['.$count.'] = '.$id.';';
                $count++;
        }
        ?>

        for (i=0;i<x.length;i++)
        {
                if (x.options[i].selected) hiddenidfield.value =
users[i];
        }
}
//-->
</script>

One thing to make sure of is that you are looping through your results
in the same order both when you create the javascript array inside the
function, and also when creating the select list. 

Then in your form have a hidden input as follows:

<input type="hidden" name="id">

And for the select list, use the onchange attribute to set the value of
the hidden input field (onchange="setEmail(this);").

You'll obviously need to update hiddenidfield.value with the proper
reference to this input in the elements collection for this form.

I'm writing this off the top of my head, so if there are any problems
let me know.  It should be pretty close though as I had to do just what
you asked a few times recently.

Cheers,
Pablo

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to