Click to See Complete Forum and Search --> : [RESOLVED] problem on onClick


cmon1011
06-15-2006, 03:20 AM
i got this code:

$save_button1 = "<input type=\"submit\" name=\"knop\" value=\"save\" onClick=\"setValues( '1' );\" class=\"formbutton\">";

$save_button2 = "<input type=\"button\" name=\"knop\" value=\"save\" onClick=\"setValues( '1' );document.location.href='cmc.php?id=$relation_id&refreshTopMenu=true&type=sales&search='\" class=\"formbutton\">";


the purpose is:
-to save the value
-go to other page

the $save_button1 can save the value, but it can't go to the other page
the $save_button2 can't save the value, but it does go to the other page

is there anyway to make the button can go both of the purpose?
thx

GaryS
06-15-2006, 04:32 AM
Are you attempting to do this with JavaScript or with PHP? (You mentioned onClick in your post... which implies JavaScript.)

cmon1011
06-15-2006, 04:39 AM
yea i guess, a bit javascript
the save_button code is at file.php (not in <script language="JavaScript" type="text/javascript"> save_button blablabla </script>)

this code:
function setValues( asButtonClicked ) {
// $ButtonClicked is used to check what action has to be performed in the php code
document.budget_sales.ButtonClicked.value = asButtonClicked ;
}
at file.tpl, it's in the javascript

GaryS
06-15-2006, 04:45 AM
Could tell you how to do it in php. I'll defer to others for the JavaScript...

cmon1011
06-15-2006, 04:58 AM
what do u mean by "how to do it in php" ?
in file.php, there's some code like this:
$save_button = "<input type=\"submit\" name=\"knop\" value=\"save\" onClick=\"setValues( '1' );\" class=\"formbutton\">";

$template->process( BUDGET_TOP, array(
lock_button => $lock_button,
save_button => $save_button,
hidden_values_money => $hidden_values_money,
.
.
.


it will go to the file.tpl
the save_button will go to :

<form method="post" action="edit_budget.php" name="budget_sales" onkeypress="checkEnter(events)">

<td class="grey" align="left">
<input type="hidden" name="relation_id" value="{relation_id}">
{save_button}
.
.
.
<input type="button" name="cancel_button" onClick="document.location='edit_relation.php?action=view&type={type}'" class="formbutton" value=[CANCEL]>
{lock_button}
</td>


if u look at the first post, if i use save_button1, it'll go to action="edit_budget.php" & it'll save some value, but if i use save_button2, it'll go to the other page but it didn't save any value..

i hope this is more clear..