0

I would like to redirect to the chosen page after having validated the form. I started this:

<form action = "planning.php?court= variable" method = "POST">.

<script>
        function courtNumber () {
            var variable = document.getElementById ("tennis_court"). value;
            alert (variable);
        }
</script>

I catch the correct value in my alert when I click on validate, now I would like to insert it in my tag.

Thank you.

0

2 Answers 2

1

You can reassign the action of the form.

function courtNumber () {
    var variable = document.getElementById("tennis_court").value;
    document.querySelector("form").action = "planning.php?court=" + encodeURIComponent(variable);
}
Sign up to request clarification or add additional context in comments.

6 Comments

Sorry, I mistyped variable as value
thank you, I did it and I replaced my code with yours but still no "planning?court = variable" in my url, variable is always null.
How are you calling courtNumber()?
In my input of the form: <input type="submit" class="btn btn-primary" value="Valider" onclick="courtnumber()">
it's ok, I saw the mistake when I post you the last message, it's courtNumber and no courtnumber, thank you very much, it's ok!
|
0

First you can add one id to your form, so you can access it in your function.

<form action = "planning.php?court= variable" method = "POST" id="myForm">
</form>

Then, in your script you can acces the action property and set the value there.

<script>
function courtNumber () 
    {
        var variable = document.getElementById("tennis_court").value;
        alert (variable);

        document.getElementById("myForm").action = "planning.php?court=" + variable;
    }
</script>

1 Comment

You're missing the planning.php part of the action in your assignment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.