How to get JavaScript value in PHP?

How do I pass a javascript variable as a get/post parameter to a .php?

  • I Have <script> var=20 </script> I want to do something like <form action=search.php?var>

  • Answer:

    Ajax! But I do not think it is exactly what you want!

Share knowldge, lets be friends. at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

This is one way: <script> var myValue = "New Value"; var myForm = document.getElementById("myForm"); var myElement = document.getElementById("myElement"); myElement.value = myValue; myForm.submit(); </script> <form id="myForm" etc. <input id="myElement" type="hidden" value="not set yet" /> etc. I'm sure there are other ways, but I know this way works.

Unca Alby

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.