demic0de
demic0de

Reputation: 1313

Submit without refresh in php

I've read a lot of post regarding the topic. I've seen lots of answers and pointing to use ajax. Is there any other way to not refresh the page on form submit?

E.g Sample form

<form method="post">
<input type="radio" name="test" value="Start">Start<br />
<input type="radio" name="test" value="Stop">Stop<br />
<input type="submit" value="GO">
</form>

Is there a javascript way of doing it without using ajax and jquery?

Thanks,

Upvotes: 2

Views: 4110

Answers (4)

Naz
Naz

Reputation: 2775

<form method="post" onSubmit="event.preventDefault()">
<input type="radio" name="test" value="Start">Start<br />
<input type="radio" name="test" value="Stop">Stop<br />
<input type="submit" value="GO">
</form>

You don't need to use any iframe for this short purpose... as you looking for a javascript methods, I will recommend you to use event.preventDefault() inside the form tag in html... it will not let the form submitted and refresh the page...

Upvotes: 0

drsndodiya
drsndodiya

Reputation: 1685

I think you may use AJAX For that it's better ways to submit form without page refresh

Upvotes: 0

Lucas Green
Lucas Green

Reputation: 3959

Yes, you can use a form embedded in an iframe.

Upvotes: 0

Mihai Iorga
Mihai Iorga

Reputation: 39704

Yes, you can use iframes:

<iframe id="myIframe" name="myIframe" width="0" height="0" frameborder="0"></iframe>
<form method="post" target="myIframe" action="script.php">
    <input type="radio" name="test" value="Start">Start<br />
    <input type="radio" name="test" value="Stop">Stop<br />
    <input type="submit" value="GO">
</form>

Upvotes: 3

Related Questions