Link to home
Start Free TrialLog in
Avatar of JuniorBee
JuniorBeeFlag for United States of America

asked on

Copy dynamic select field value to a text field in another form on the same page

I have a select field that is created on the fly and there are 2 forms on the page.  I don't want to have the select field on the page twice in both forms but I need that value for both forms, whichever the user selects to submit.

So I would like to have the select field display in the first form, then whatever is selected, copies to a hidden text field in the 2nd form.

I am attaching thee code that displays the drop down/select field
<?php // select drop-downs?
if($attr_option == 1){
echo get_attribute_dropdown($post->ID);
}
elseif($attr_option == 2){
echo get_attribute_dropdown($post->ID,2,$basis_price);						else{}													
?>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of asafadis
asafadis
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JuniorBee

ASKER

I prefer the javascript method since it's faster to implement but it doesn't seem to work.
Can we see what you're trying to do?
I seem to have gotten it to work, thanks!
oh is there a way to get it to load when the page loads also?  So that the hidden form has the same thing as the first selection in the dropdown?
Try:
window.onload = function() {
        var select = document.getElementById('mySelect');
        var hidden = document.getElementById('myHiddenInput');
        select.onchange = function() {
            hidden.value = this.value;
        };

        hidden.value = select.value;
    };

Open in new window

thanks!