Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jun 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Assigning multiple name=values with one select box...help?

    I'm not sure how to do this as I am NOT a javascript Guru. But if I were to have a select box, and multiple options, how would I assign two different name=value combinations to that select box to be passed onto the next page and have them change as the user changes their choice in the select box?

    i.e. I have a variable named "currency" and a variable named "amount"

    when the user selects a new currency in the select box the values of both "currency" and "amount" change to accomodate the user's choice without reloading the page, and have both variables be passed on via the form.

    How do I do this?

    Any help is greatly appreciated!

    )O( Cloudrunner )O(
    Last edited by Cloudrunner; 06-03-2005 at 01:42 AM.

  • #2
    New to the CF scene
    Join Date
    Jun 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Anyone...Truth is I'm Javascript stupid folks, and I have not a CLUE on how to get this to work properly....

    I have this thus far, and while it works in a standalone presence, when I try to add it to other pages, it chokes and I get nothing...

    This is the test page...
    PHP Code:
    <script language="javascript">
    function makeAmount(){
        var selVal = document.donate.currency_code[document.donate.currency_code.selectedIndex].value;
        if (selVal == 'USD') document.donate.amount.value = 5;
        else if (selVal == 'AUD') document.donate.amount.value = 10;
        else if (selVal == 'CAD') document.donate.amount.value = 15;
    }
    </script>
    <?
    if (empty($_POST)){
    ?>
    <form name="donate" action="test.php" method="post">
        <input type="hidden" name="amount" value="1">
        <select name="currency_code">
            <option value="USD">US Dollar $5</option>
            <option value="AUD">Australian Dollar = $10</option>
            <option value="CAD">Canadian Dollar = $15</option>
        </select>
        <input type="submit" onClick="makeAmount()">
    </form>
    <?
    } else {
        echo 
    $_POST['currency_code']." -- ".$_POST['amount'];
    }
    ?>
    Like I said, when I run this it works fine, but when I try to go live with it on a real page with true html / xml constructs, it chokes, no errors, but the "amount" variable is not passed within the $_POST global as if the form wrote it which is what I need to do...

    Any help is appreciated...

    Thanks

    )O( Cloudrunner )O(
    Last edited by Cloudrunner; 06-03-2005 at 11:48 PM.

  • #3
    Regular Coder
    Join Date
    Feb 2005
    Posts
    400
    Thanks
    0
    Thanked 0 Times in 0 Posts
    A submit can be triggered by pressing enter, as well as clicking. So having your function as an onclick on the submit button is shaky. Better would be to have it as an onchange on the select, or as an onsubmit on the form.

    If that doesn't help, post back showing the code of the non-working page.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •