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
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;
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.