开发者

HTML: How would I ensure the correct submit input was triggered when pressing the enter key?

开发者 https://www.devze.com 2023-02-19 00:08 出处:网络
I have one form with three submit inputs (coupon code, redeem gift card,form submit). The inputs are placed on the page in the order I just mentioned so when the user presses enter the coupon code is

I have one form with three submit inputs (coupon code, redeem gift card,form submit). The inputs are placed on the page in the order I just mentioned so when the user presses enter the coupon code is always being submitted. Is the there a way to have only the form submit triggered when the enter key is pressed? I would like to accomplish this without any client-side coding if possible.

<form>
    <!-- start section 1 -->
    <input type="text" name="input1" id="input1" /><br />
    <input type="text" name="input2" id="input2" /><br />
    <!-- end section 1 -->

    <!-- start section 2 -->
    <input type="text" name="couponCodes" id="couponCodes" /><br />
    <input type="submit" name="orderBy" id="orderBy" valeue="Apply" /><br />
    <!-- end section 2 -->

    <!-- start section 3 -->
    <input type="text" name="giftCards" id="giftCards" /><br />
    <input type="submit" name="orderBy" id="orderBy" valeue="Apply" /><br />
    <!-- end section 3 -->

    <!-- start section 4 -->
    <input type="text" name="input3" id="input3" /><br />
    <input type="submit" name="orderBy" id="orderBy" valeue="Place Order" />
    <!-- end section 4 -->
</form>

What I am trying to do is have the submit inputs in section 2 and 3 not get triggered when the enter key is pressed. I want the submit input in section 4 to be the one triggered when the enter key is pressed. I would rathe开发者_运维百科r not change the Apply submits to an since this defines another field and is not handled by the PHP form validation script. <button></button> is what I have tried using but when the enter key is pressed the Apply buttons are still being triggered.


May be some code can help but a easy way to do it is set your "form submit" in type="submit" and your two other coupon code and redeem gift card in type="button".

0

精彩评论

暂无评论...
验证码 换一张
取 消