Jump to content

javascript submit form button


arbitter

Recommended Posts

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

  • 2 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.