Forum Moderators: open

Message Too Old, No Replies

Confirm Button Function

         

ayushchd

5:52 pm on May 21, 2007 (gmt 0)

10+ Year Member



<input type="button" name="Button" value="Sell" onClick="return confirm('Are you sure you want to sell these shares?'); buy('txtHint1<?php echo $new_count;?>', '<?=$row['company']?>', qty.value, '<?=$row['quantity']?>', 'sell', '<?=$row['id']?>'); update('update');">

I want it to return a confirm box when clicked, and if the user clicks ok, it shud execute the function buy....its not wokring

eelixduppy

7:22 pm on May 21, 2007 (gmt 0)



Why don't you create a separate function to be called when the button is clicked. In this new function, you first prompt the user with a question, and then depending on the response, handle accordingly.

Fotiman

8:21 pm on May 21, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



This is really a poor separation of content and behavior. This would better be realized with unobtrusive JavaScript. Also, keep in mind that a "button" input type won't do anything for users with JavaScript disabled.

However, the quick and dirty approach:


<input type="button" name="Button" value="Sell"
onClick="function(){
if (confirm('Are you sure you want to sell these shares?')) {
buy( 'txtHint1<?php echo $new_count;?>',
'<?=$row['company']?>',
qty.value,
'<?=$row['quantity']?>',
'sell',
'<?=$row['id']?>' );
update('update');
}
};"
>