URGENT - Javascript or simple PHP - grab a value from a form and display below?
-
I have a form that has a dropdown menu of 1>>20. Each number = $20. eg if you select 1, that = $20; if you select 5, that =$100. Directly under this dropdown menu I want to display the monetary value. e.g. if you select 5, 5 shows in the dropdown menu but displays $100 underneath it. How do you do this SIMPLY? In either javascript or simple php... I don't want to have to click a button to show the monetary value, or to refresh if you change the drop down menu number.
-
Answer:
As said before you could use Javascript to do that, although Im not sure what exactly you want, but I wrote this script which does what you want... <script type="text/javascript"> function calculation( object ) { var number = object.value; var total = number * 20; var result_div = document.getElementById( 'result' ); result_div.innerHTML = '$' + total; } </script> <body> <select name="options" onchange="calculation( this )"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> </select> <div id="result"> </div> </body> Of course you need to put the <html> tags and if you need to change the names you can do so. This script works on firefox 1.5, opera 8.5 and internet explorer 7 beta 2.
1234qwer... at Yahoo! Answers Visit the source
Other answers
To do this without a reload would have to be done with javascript. PHP is a server side language and wouldnt affect anything until you load the page. Unfortunately I couldnt tell you how to do it in javascript.
Rafe
Using javascript: <html> <head> <script language="javascript"> function DropboxChange() { var SelectedValue = document.Form1.select1.value; alert(SelectedValue); } </script> </head> <body> <form id="Form1" method="post"> <SELECT id="Select1" onchange="DropboxChange()"> <OPTION selected value=""></OPTION> <OPTION value="20">1</OPTION> <OPTION value="40">2</OPTION> </SELECT> </form> </body> </html> here your value is displayed in a popup window. you can also display it on the form if you choose. hope this helps
Ronnie
Related Q & A:
- How to return a value from .ashx file to javascript in a variable?Best solution by forums.asp.net
- How to change javascript values to php?Best solution by stackoverflow.com
- How to call Javascript function in PHP?Best solution by Stack Overflow
- How do I get a value from a JObject?Best solution by Stack Overflow
- What is an easy code for a form in PHP?Best solution by Stack Overflow
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
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.