Page 1 of 1

[SOLVED] Multiple Buttons on One Form

Posted: Thu Aug 19, 2004 12:58 pm
by TNIDBMNG
I have a form called Schedule, and I have 2 button on the form. Each button needs to do something different. I read somewhere that you can call the forms action in the onClick part of the button but it's not working for me. Can someone tell me what I'm doing wrong or how to have to different actions for different buttons. Below is my code.

Code: Select all

<?php
echo '<tr bgcolor="#FFFFFF"><form name="schedule" action="" method="post"><td width="10%" bordercolor="#000000" >'. $date. '</td>';
echo ("<td width='21%'><a href='itschedule_edit.php?priority=".$id."'>".$description. "</a></td>");
echo '<td width="34%">' .$strnotes.'<input type="Text" name="txtNote'.$id.'" size="70%">&nbsp;';
echo '<input type="submit" name="addnote'.$id.'" value="Insert" onClick=this.form.action="itschedule_edit.php?id='.$id.'"></td>';
echo '<td width="8%" align="center">' .$percentComplete. '%</td>';
echo '<td width="5%" align="center">' .$Completed. '</td>';
echo '<td width="10%">' .$datecompleted. '</td>';
echo '<td width="10%">' .$dateverified. '</td>';
echo '<td width="2%"><input type="submit" name="update'.$id.'" value="Edit">';
echo '</form></tr>';
?>
I'm not receiving any errors but when the addnote button is pressed nothing happens.

Posted: Thu Aug 19, 2004 1:05 pm
by feyd
try:

Code: Select all

onclick="this.form.action=''itschedule_edit.php?id='.$id.'''"
although, it may be better to stick that into a function for easier calling, if it's done in multiple places like it looks to be..

Posted: Thu Aug 19, 2004 1:31 pm
by TNIDBMNG
I actually just started placing this into a function when you replied but it's still not working.

Here is my code.

Code: Select all

<?php
echo '<tr bgcolor="#FFFFFF"><form name="schedule" action="" method="post"><td width="10%" bordercolor="#000000" >'. $date. '</td>';
echo ("<td width='21%'><a href='itschedule_edit.php?priority=".$id."'>".$description. "</a></td>");
echo '<td width="34%">' .$strnotes.'<input type="Text" name="txtNote'.$id.'" size="70%">&nbsp;';
echo '<input type="submit" name="addnote'.$id.'" value="Insert" onClick="addNotes()"></td>';
echo '<td width="8%" align="center">' .$percentComplete. '%</td>';
echo '<td width="5%" align="center">' .$Completed. '</td>';
echo '<td width="10%">' .$datecompleted. '</td>';
echo '<td width="10%">' .$dateverified. '</td>';
echo '<td width="2%"><input type="submit" name="update'.$id.'" value="Edit">';
echo '</form></tr>';
?>
The function is

Code: Select all

&lt;script language="javascript"&gt;

function addNotes()&#123;
	
   this.form.action = 'itschedule_edit.php?id='.$id.''

&#125;

&lt;/script&gt;
What am I doing wrong?

Posted: Thu Aug 19, 2004 1:41 pm
by feyd

Code: Select all

onclick="addNotes(this.form, ''' . $id . ''')"

Code: Select all

function addNotes(frm,id)
&#123;
  frm.action = 'itschedule_edit.php?id=' + id;
&#125;

Posted: Thu Aug 19, 2004 1:54 pm
by TNIDBMNG
That worked perfectly thanks so much.