Sinbad_Sakic Posted November 4, 2008 Share Posted November 4, 2008 Hi to everyone I have two problems: - on a single webpage, I have a few menu lists. Each of them has a number as value. At the bottom of the page, I would like to calculate what visitors have chosen For example: <html> <body> <form id="form1" name="form1" method="post" action=""> <label> <select name="one" id="one"> <option value="100">Something 1</option> <option value="200">Something 2</option> <option value="300">Something 3</option> </select> </label> <br /> <label> <select name="two" id="two"> <option value="100">Something 1</option> <option value="200">Something 2</option> <option value="300">Something 3</option> </select> </label> <label> <br /> <select name="three" id="three"> <option value="1000">Something 1</option> <option value="600">Something 2</option> <option value="900">Something 3</option> </select> </label> <br /> Total: </form> </body> </html> As you can see, each of the menu list items has a value. How to make it automatically calculate the values? -my second question is about images Lets say I have four images on my screen: <html> <body> <img name="" src="" width="32" height="32" alt=""> <img name="" src="" width="32" height="32" alt=""> <img name="" src="" width="32" height="32" alt=""> <img name="" src="" width="32" height="32" alt=""> <img name="" src="" width="32" height="32" alt=""> </body> </html> And a variable defined at the beggining of the document - $variable = "first image"; Is it possible to add something like onClick event to images, so when the visitors click on one of them the $variable changes to "second image", "thrid image" or "fourth image"? Thanks in any case Batric Link to comment https://forums.phpfreaks.com/topic/131314-ajax-calculator-and-image-trigger/ Share on other sites More sharing options...
Sinbad_Sakic Posted November 4, 2008 Author Share Posted November 4, 2008 Anyone? Link to comment https://forums.phpfreaks.com/topic/131314-ajax-calculator-and-image-trigger/#findComment-682268 Share on other sites More sharing options...
xtopolis Posted November 5, 2008 Share Posted November 5, 2008 I don't see how this is Ajax. For the first problem: <script type="text/javascript"> function updateTotal() { var ele = document.getElementById("total"); var s = document.getElementsByTagName("select"); var total = 0; for(i=0;i<s.length;i++) { var x = parseInt(s[i].value); if(!isNaN(x)) { total += x;} } ele.innerHTML = total; } </script> and I changed "total" to: Total:<span id="total"></span> For the second problem.. You can't change a PHP variable once the page has made it to the client. What are you trying to do... Link to comment https://forums.phpfreaks.com/topic/131314-ajax-calculator-and-image-trigger/#findComment-682593 Share on other sites More sharing options...
Sinbad_Sakic Posted November 5, 2008 Author Share Posted November 5, 2008 Thanks for the first issue! I have already found something similar to what I wanted. About the second problem. As I explained, there are several images on that page. Depending on which one the user clicks, I need a variable to be changed. When the first image is clicked - $variable="first image"; When the second image is clicked - $variable="second image"; Etc If not ajax, then javascript? Link to comment https://forums.phpfreaks.com/topic/131314-ajax-calculator-and-image-trigger/#findComment-682767 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.