0

I want to disable a button after the button onclick and then enable the other one .

echo '<input type="text" id="txtbox1" name="tb1" value="'.$value.'" />';
echo '<input type="submit" id="btn1" name = "btnstart" value="START" onClick="this.disabled=true;"/><input type="submit" id="btn2" name = "btnend" value="End" onClick="this.disabled=true;"/>';

In this case, i can only disable the button but the rest of the process skipped. I cannot update the input textbox value.

Also, How can i disable the btn2 the before onclick btn1?

$value= $_POST['tb1']; 
echo '<form name="f1" method="POST" action="">';
echo '<input type="text" id="txtbox1" name="tb1" value="'.$value.'" />';
echo '<input type="submit" id="btn1" name = "btnstart" value="START" onClick="this.disabled=true;"/><input type="submit" id="btn2" name = "btnend" value="End" onClick="this.disabled=true;"/>';
echo '</form>';
echo '</td>';

if ( isset( $_POST['tb1'] ) ) {
$new = $value *12;
}
2
  • What exactly you want?at first both buttons should be enabled then after clinking on btn1 it should be disabled and btn2 should be enabled? Commented Jan 15, 2014 at 4:37
  • I want to enable the btn1 and disable btn2 when the page loaded. After clicking btn1 , btn1 disable and then enable btn2. After clicking btn2, btn2 disable also. Commented Jan 15, 2014 at 4:41

4 Answers 4

1

Try this:

<input type="submit" id="btn1" name = "btnstart" value="START" onClick="document.getElementById('btn2').disabled=false;this.disabled=true;"/>
<input type="submit" id="btn2" name = "btnend" value="End" onClick="this.disabled=true;" disabled/>

Working example: jsfiddle

Sign up to request clarification or add additional context in comments.

6 Comments

I did it thank you. but I cant get the textbox value if(isset($_POST['btnstart'] , echo null .Can u help me?
If it is what you wanted please accept the answer :) show the full code where you want to get the textbox value.
in $_POST the value is the name of the textbox which you want. In your case it will be $_POST['tb1']
I can send you the full code in pic , are u interested in it ?
remove $value= $_POST['tb1']; from top and place it inside your if statement before calculating $new.
|
1

Can you try this,

How can i disable the btn2 at the before onclick btn1?

Added onClick="document.getElementById(\'btn2\').disabled=true;this.disabled=true;"

    echo '<input type="text" id="txtbox1" name="tb1" value="'.$value.'" />';
    echo '<input type="submit" id="btn1" name = "btnstart" value="START" onClick="document.getElementById(\'btn2\').disabled=true;this.disabled=true;"/>
    <input type="submit" id="btn2" name = "btnend" value="End" onClick="this.disabled=true;"/>';

2 Comments

I did it thank you. but I cant get the textbox value if(isset($_POST['btnstart'] , echo null .Can u help me?
to get textbox value echo $_POST['tb1'];
0

try jquery

first load the html with submit button 2 disabled

echo '<input type="text" id="txtbox1" name="tb1" value="" />';
echo '<input type="submit" id="btn1" name = "btnstart" value="START" /><input type="submit" id="btn2" name = "btnend" value="End" disabled="disabled" />';

then using jquery

   $(document).ready(function(){
      $("input[type='submit']").click(function(){

          $("input[type='submit']").prop('disabled',false);
          $(this).prop('disabled',true);
      });
   });

disable the clicked submit button and enable other submit button

Comments

-1

I placed an example in jQuery. jQuery is much easier then normal Javascript. Dont forget that jQuery is still javascript but then with functions that are already named to do their function:

.click() //When clicked
.next() //Next element/attribute
.mouseenter //When hover
.text() //Set the text

$('#mydiv').text('Contains this text');

Do the codecadamy.com training, its very helpfull, easy to follow and very quick.

I placed an example in jQuery for you: JSFiddle

2 Comments

No need to do so much coding when it can be done in a single line. :)
Its not about one line, what im saying is using jQuery is much easier. So if a starter needs something that gets done immediatly, learning jQuery is easier then learning JS ;)

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.