Jump to content

On enter, submit second form submit???


Tenaciousmug

Recommended Posts

Okay I am doing a banking system. I have a deposit and withdraw submit button in the same form.. thing is. When they are entering into the deposit field and hit "enter", it works fine since I guess the deposit is the default submit button. When they fill in the withdraw and hit "enter", it tries to enter for the deposit button.

I want it when they are on the withdraw input field and hit enter, to submit the "withdraw" button, not the deposit.

 

How do I go about doing this? I feel like it's something with Javascript or something.

 

<form action="'.$_SERVER['SCRIPT_NAME'].'" method="post">
	<div class="row clearfix">
			<div class="two-row left">
					<label>Deposit: </label>
					<input type="text" name="deposit_amt" />
			</div>
			<div class="two-row">
					<label>Withdraw: </label>
					<input type="text" name="withdraw_amt" />
			</div>
	</div>
	<div class="row clearfix">
			<div class="two-row left">
					<input type="hidden" name="account" value="'.$bank['bank_name'].'" />
					<input type="submit" name="deposit" value="Deposit" class="button" />
			</div>
			<div class="two-row">
					<input type="hidden" name="account" value="'.$bank['bank_name'].'" />
					<input type="submit" name="withdraw" value="Withdraw" class="button" />
			</div>
	</div>
</form>

 

I already tried rearranging the form so the deposit button is after the deposit input field and the withdraw button is after the withdraw input field, but it doesnt do anything.

Link to comment
https://forums.phpfreaks.com/topic/263065-on-enter-submit-second-form-submit/
Share on other sites

try giving both submit buttons the same name, say btnSubmit, then test the value

switch ($_POST['btnSubmit'])  {
    case 'Deposit':
             // deposit code
             break;
    case 'Withdraw':
             // withdrawal code
             break;
}

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.