Rocco The Taco
Rocco The Taco

Reputation: 3797

Include form select value in URL

I have a javascript function that currently changes the Submit action based on value of a variable called currentVal. I do have a select within this form with an ID of TRADE_IN that I also want to pass to the next page. How do I alter/add to this javascript to also submit this form select into the url so I can perform a $trade = $_REQUEST['TRADE_IN']; on the next page as well?

function changeSubmit(currentVal, id) {
    if(currentVal < 5) {
        $('#avgSubmit'+id).val('myVolvo.php?plan=gold&age=1-4 years');
    } else if(currentVal >=5 && currentVal < 10) {
        $('#avgSubmit'+id).val('myVolvo.php?plan=gold&age=5-9 years');
    } else {
        $('#avgSubmit'+id).val('myVolvo.php?plan=gold&age=10 years');
    }
}

Upvotes: 0

Views: 207

Answers (2)

Sebastian Breit
Sebastian Breit

Reputation: 6159

Jason's answer could work. You could store it in your $_SESSION var too!

Upvotes: 1

Jason
Jason

Reputation: 1220

Seems to me you could simply have this:

<form action="myVolvo.php" method="get">
    <input type="hidden" name="plan" value="gold" />
    <select name="age">
        <option value="1-4 years">1-4 years</option>
        <option value="5-9 years">5-9 years</option>
        <option value="10 years">10 years</option>
    </select>
</form>

Where the hidden "plan" could also be a visible form element if needed.

Does this make sense, or am I missing something?

Upvotes: 0

Related Questions