chris.bacon Posted March 11, 2011 Share Posted March 11, 2011 Ok folks on my form i use javascript on a dropdown box (months of the year) to show/hide following dropdown boxes using css i.e box1 = 1-28 days default hide this dropdown box2 = 1-30 days default hide this dropdown box3 = 1-31 days default show this dropdown the correct dropdown box will be shown and the others hidden according to the month selected this works fine. JavaScript <script type="text/javascript"> <!-- // var small = 1-28 days // var medium = 1-30 days // var large = 1-31 days function ToggleDays(id) { var small = document.getElementById('short'); var medium = document.getElementById('medium'); var large = document.getElementById('long'); var value = id.options[id.selectedIndex].value; if(value == 2) { small.style.display = "inline"; medium.style.display = "none"; large.style.display = "none"; } if( value==2 || value==4 || value==6 || value==9 || value==11 ) { if(value == 2) { small.style.display = "inline"; medium.style.display = "none"; large.style.display = "none"; } else { small.style.display = "none"; medium.style.display = "inline"; large.style.display = "none"; } } else { small.style.display = "none"; medium.style.display = "none"; large.style.display = "inline"; } } //--> </script> HTML form (part of) <form name="feedback" action="newformverify.php" method="POST" onsubmit='return formValidator()'> <fieldset> <legend>Feedback</legend> <p><label>Name</label> <input id="name" type="text" name="name"/></p> <p><label>Centre</label> <input id="centre" type="text" name="centre"/></p> <p><label>Date of meeting</label> <select id="month" name="month" size="1" onchange="ToggleDays(this);"> <option value=0><?php echo date("F")?></option> <option value=1>January</option> <option value=2>February</option> <option value=3>March</option> <option value=4>April</option> <option value=5>May</option> <option value=6>June</option> <option value=7>July</option> <option value=8>August</option> <option value=9>September</option> <option value=10>October</option> <option value=11>November</option> <option value=12>December</option> </select> I want to use php to gather all info from form together and send in an email using the mail function. however when i post from the select it posts the option value and not the text is there any way to stop this? <?php session_start(); $month=$_POST['month']; echo ("$month"); //this displays either a 0 or 1 etc ?> Link to comment https://forums.phpfreaks.com/topic/230362-php-post-and-javascript/ Share on other sites More sharing options...
AbraCadaver Posted March 11, 2011 Share Posted March 11, 2011 If you supply a value for an option then it will be posted. If not, the text will be posted. So, as I see it you have several "options" 1. Change the value to use the month text which will require changing the javascript, or 2. Change the value to id so there is no value and use the id in the javascript, or 3. Create a function that is fired onsubmit() that reassigns the text to the value: month.options[month.selectedIndex].value = month.options[month.selectedIndex].text; Link to comment https://forums.phpfreaks.com/topic/230362-php-post-and-javascript/#findComment-1186278 Share on other sites More sharing options...
chris.bacon Posted March 11, 2011 Author Share Posted March 11, 2011 Nice Thanks that really helped! just a quick one im sure this is not possible as i have never had the need but can i call two separate functions onsubmit()? Link to comment https://forums.phpfreaks.com/topic/230362-php-post-and-javascript/#findComment-1186285 Share on other sites More sharing options...
AbraCadaver Posted March 11, 2011 Share Posted March 11, 2011 Quote Nice Thanks that really helped! just a quick one im sure this is not possible as i have never had the need but can i call two separate functions onsubmit()? You can call one that then calls the other two: onSubmit="return submit_check();" function submit_check() { return func1() && func2(); } Or: onSubmit="return func1() && func2();" Link to comment https://forums.phpfreaks.com/topic/230362-php-post-and-javascript/#findComment-1186303 Share on other sites More sharing options...
Mahngiel Posted March 11, 2011 Share Posted March 11, 2011 could also add name="optionvalue" to the form. Link to comment https://forums.phpfreaks.com/topic/230362-php-post-and-javascript/#findComment-1186316 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.