Jump to content
ravi_k

submit and hide

Recommended Posts

Hi

I am trying to submit the form and also when start is pressed, it should be disabled and only stop to be avialable.

I tried below code but submit form is not happening

<form action="/action_page.php" method="post">
Testing:    <input name="ip" id="ip" type="text" min="0" max="255">


<input type="submit"  id="start" value="start" onclick="myFunction1()">
<input type="submit"  id="stop"  value="stop"    onclick="myFunction2()">
</form>


<script>

function myFunction1() {
     document.getElementById("start").disabled = true;
     document.getElementById("stop").disabled = false;
}
function myFunction2() {
     document.getElementById("start").disabled = false;
     document.getElementById("stop").disabled = true;
}

</script>

Thanks with Regards

Ravi K

Share this post


Link to post
Share on other sites

You're disabling the button right when it is clicked, so it won't make the form submit, but if you don't disable it then the form will submit, leaving the page and resetting the button states anyway. What is your end goal with this?

Share this post


Link to post
Share on other sites

Click 'start' submitted-> gone!...disable whaaaaaaoooooooo......

Click 'stop' submitted->gone! ...enable whaaaaaaoooooooo......

Once the form is submitted to another page, it wouldn't get a chance to Disable/Enable anything as it goes instantly to the URL set in the 'action' attribute.

The form page is left on submission, and when return to, if you had! managed to Disable/Enable anything! They will be reset to there default state.

Share this post


Link to post
Share on other sites

Hi

I have changed my code as below.

<form action="/action_page.php" method="post">
Testing: &emsp;&nbsp;&nbsp;<input name="ip" id="ip" type="text" min="0" max="255">
<input type="submit" value="Start">
<input type="submit" value="Stop">
</form>

How can i differentiate which button is pressed on server side  whether its start or stop.

Please suggest

 

Thanks with Regards

Ravi K

Share this post


Link to post
Share on other sites

Give each button a name, then check on the server whether the name exists in the $_POST array and what value it has.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×