arbitter Posted November 27, 2010 Share Posted November 27, 2010 I feel kind of stupid posting another topic this fast, but I can't find a solution. So I want a table row to submit a form. Currently this is what I have for the table row: <tr> <td id='submit' colspan='2' onclick="submitForm()" style='cursor:pointer'><div class='green'>Submit.</div></td> </tr> the javascript is: function submitForm() { document.getElementById("enkel").submit(); } and the form is: <form id='enkel' method='post' action='test.php'> <select name='begindag'><?php for($i=1; $i<=31; $i+=1){echo "<option value='$i'>$i</option>";} ?> </select> <select name='beginmaand'><?php for($i=1; $i<=12;$i+=1){echo "<option value='$i'>$months[$i]</option>";} ?></select> </form> This all works fine. If I say if(isset($_POST['begindag'])){ \\execute script } It'll work fine. But how can I give this submit another value? eg when I use a pure html form; in my php code i'd check if the submit button was clicked: if(isset('$_POST['submit'])){..} I'd like to use this method here too. How can I add a value to the submit button that's posted as well? Also; it would be nice if this value could be adjusted by an onclick somewhere... Here's the whole code: <html> <?php session_start(); if(isset($_POST['begindag'])){echo "check!";} ?> <script type='text/javascript'> function hideShow(id) { var object = document.getElementById(id).style if (object.display == "none") { object.display = "table-row"; } else { object.display = "none"; } } function submitForm() { document.getElementById("enkel").submit(); } </script> <script type='text/css'> </script> <?php $months = array('1'=>'Januari','2'=>'Februari','3'=>'Maart','4'=>'April','5'=>'Mei','6'=>'Juni','7'=>'Juli','8'=>'Augustus','9'=>'September','10'=>'Oktober','11'=>'November','12'=>'December'); ?> <form id='enkel' method='post' action='test.php'> <table border='1' id='foo'> <tr> <td>Dag:</td> <td><select name='begindag'><?php for($i=1; $i<=31; $i+=1){echo "<option value='$i'>$i</option>";} ?> </select></td> </tr> <tr> <td>Maand:</td> <td><select name='beginmaand'><?php for($i=1; $i<=12;$i+=1){echo "<option value='$i'>$months[$i]</option>";} ?></select></td> </tr> <tr id='vraag'> <td colspan='2' onclick="hideShow('vraag');hideShow('datum2');hideShow('datum');hideShow('datum3')" align='center' style='cursor:pointer'>Einddatum geven?</td> </tr> <tr id='datum' style='display:none;'> <td>Einddag:</td> <td><select name='einddag'><?php for($i=1; $i<=31; $i+=1){echo "<option value='$i'>$i</option>";} ?> </select></td> </tr> <tr id='datum2' style='display:none;'> <td>Eindmaand:</td> <td><select name='eindmaand'><?php for($i=1; $i<=12;$i+=1){echo "<option value='$i'>$months[$i]</option>";} ?></select></td> </tr> <tr id='datum3' style='display:none'> <td colspan='2' onclick="hideShow('vraag');hideShow('datum');hideShow('datum2');hideShow('datum3')" align='center' style='cursor:pointer'>Geen einddatum geven</td> </tr> <tr> <td id='submit' colspan='2' onclick="submitForm()" style='cursor:pointer'><div class='green'>Activiteit toevoegen.</div></td> </tr> <tr> <td colspan='2' onclick="submitForm('dubbel')" style='cursor:pointer'>Activiteit toevoegen.</td> </tr> </table> </form> </html> Link to comment https://forums.phpfreaks.com/topic/219974-javascript-submit-form-button/ Share on other sites More sharing options...
ohdang888 Posted November 28, 2010 Share Posted November 28, 2010 i don't understand why would require a "submit" key in post, but if need be, you'd just a hidden input element in the form <input type="hidden" name="submit" value="yes" /> Link to comment https://forums.phpfreaks.com/topic/219974-javascript-submit-form-button/#findComment-1140464 Share on other sites More sharing options...
arbitter Posted November 28, 2010 Author Share Posted November 28, 2010 Well I find it safer... And ofcourse, that I didn't come up with that... Is it possible to make the name value changeable using javascript? Link to comment https://forums.phpfreaks.com/topic/219974-javascript-submit-form-button/#findComment-1140554 Share on other sites More sharing options...
ohdang888 Posted November 28, 2010 Share Posted November 28, 2010 Well I find it safer... Its no safer than checking an input field. Link to comment https://forums.phpfreaks.com/topic/219974-javascript-submit-form-button/#findComment-1140690 Share on other sites More sharing options...
arbitter Posted December 12, 2010 Author Share Posted December 12, 2010 Well I find it safer... Its no safer than checking an input field. just for a check; if a user submit's a form, only the input's from within that form get sent, right? Link to comment https://forums.phpfreaks.com/topic/219974-javascript-submit-form-button/#findComment-1146123 Share on other sites More sharing options...
ohdang888 Posted December 12, 2010 Share Posted December 12, 2010 Well I find it safer... Its no safer than checking an input field. just for a check; if a user submit's a form, only the input's from within that form get sent, right? right. Link to comment https://forums.phpfreaks.com/topic/219974-javascript-submit-form-button/#findComment-1146342 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.