8

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 ?

6
  • what is the generated name of your form? Commented Jan 4, 2014 at 9:17
  • You want to submit the form on Click event? 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. Commented Jan 4, 2014 at 9:18
  • -This- may be useful Commented Jan 4, 2014 at 9:19
  • buttons inside a form can submit form without any onclick event Commented Jan 4, 2014 at 9:30

1 Answer 1

19

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

<button type="submit" name="<?php echo $name; ?>">Submit</button>
Sign up to request clarification or add additional context in comments.

1 Comment

submit is the default type for a button element, you can omit the attribute entirely.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.