[SOLVED] Multiple Buttons on One Form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
TNIDBMNG
Forum Newbie
Posts: 21
Joined: Wed Aug 18, 2004 12:22 pm

[SOLVED] Multiple Buttons on One Form

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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..
TNIDBMNG
Forum Newbie
Posts: 21
Joined: Wed Aug 18, 2004 12:22 pm

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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;
TNIDBMNG
Forum Newbie
Posts: 21
Joined: Wed Aug 18, 2004 12:22 pm

Post by TNIDBMNG »

That worked perfectly thanks so much.
Post Reply