twilitegxa Posted September 27, 2008 Share Posted September 27, 2008 What is the coding for adding form fields together and updating a blank text box with that value? Say I have three different pulldown boxes and I want to know, before submiting, how much these choices add up to when the user chooses their choices. Can a PHP script be written to accomplish this or must it be done with JavaScript? I prefer PHP, if possible. Anyone know how to do this? Quote Link to comment Share on other sites More sharing options...
peranha Posted September 27, 2008 Share Posted September 27, 2008 If possible, it will have to be done with javascript as PHP is server side. Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted September 27, 2008 Author Share Posted September 27, 2008 Okay, well how would I do it with JavaScript? Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted September 27, 2008 Author Share Posted September 27, 2008 Someone else helped me. Thanks! Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted September 27, 2008 Author Share Posted September 27, 2008 Someone helped me with the JavaScript for this particular problem, but I still need the PHP part. Any help out there? How do I validate with PHP when the user puts in the values in the dropdon boxes? The total needs to equal 12 before submitting. Quote Link to comment Share on other sites More sharing options...
xtopolis Posted September 27, 2008 Share Posted September 27, 2008 <select name="select1"> <option value="1">1</option> </select> <select name="select2"> <option value="1">1</option> </select> $s1val = $_POST['select1']; $s2val = $_POST['select2']; if(($s1val + $s2val) == 12){ echo 'They equal 12.'; }else{ // Not 12.. } Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted September 27, 2008 Author Share Posted September 27, 2008 Can I put this code on the same page so that is validates this before going to the next page? I am actually going to be using sessions to connect to several other pages, but I am just trying to build the page first. So I have a JavaScript that checks for validation, I just need the PHP script to be able to do it on the same page before going to the next page, since this information will be carried over and not submitted until several pages later. What do you think? Can the validation be done on this page? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.