最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Use a submit <button> instead of <input> button - Stack Overflow

programmeradmin1浏览0评论

i want to submit a form with <button> instead of <input>. I know a <button> cant handle the form like a submit <input> and i have to use the onclick method.

I tried several things but it doesn't work

<button name="<?php echo $name; ?>" onclick="document.<?php echo $this->action; ?>.submit()"> ... ( Action URL of the form )
<button name="<?php echo $name; ?>" onclick="document.iso<?php echo rand(); ?>.submit()">... ( name of the form )
<button name="<?php echo $name; ?>" onclick="window.location.href='<?php echo $this->action; ?>'">... ( Action url of the form )

Does someone know an answer ?

i want to submit a form with <button> instead of <input>. I know a <button> cant handle the form like a submit <input> and i have to use the onclick method.

I tried several things but it doesn't work

<button name="<?php echo $name; ?>" onclick="document.<?php echo $this->action; ?>.submit()"> ... ( Action URL of the form )
<button name="<?php echo $name; ?>" onclick="document.iso<?php echo rand(); ?>.submit()">... ( name of the form )
<button name="<?php echo $name; ?>" onclick="window.location.href='<?php echo $this->action; ?>'">... ( Action url of the form )

Does someone know an answer ?

Share Improve this question edited Jan 4, 2014 at 9:19 Karuppiah RK 3,9649 gold badges41 silver badges85 bronze badges asked Jan 4, 2014 at 9:15 bobbybackblechbobbybackblech 1,8866 gold badges20 silver badges22 bronze badges 6
  • what is the generated name of your form? – 23tux Commented Jan 4, 2014 at 9:17
  • You want to submit the form on Click event? – Jenson M John Commented Jan 4, 2014 at 9:17
  • 3 "I know a <button> cant handle the form like a submit <input>" - you know wrong. Buttons submit forms. – Quentin Commented Jan 4, 2014 at 9:18
  • -This- may be useful – Blundering Philosopher Commented Jan 4, 2014 at 9:19
  • buttons inside a form can submit form without any onclick event – Mahfud Harun Commented Jan 4, 2014 at 9:30
 |  Show 1 more comment

1 Answer 1

Reset to default 19

You can use the type="submit" like property of button

<button type="submit" name="<?php echo $name; ?>">Submit</button>
发布评论

评论列表(0)

  1. 暂无评论