asmith Posted January 17, 2008 Share Posted January 17, 2008 guys it is been a while i'm having this problem, i get similar codes, but none work correctly . <?php if (isset($_POST[submit1])) { echo "111"; } elseif (isset($_POST[submit2])) { echo "222"; } echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post">'; echo '<input type="submit" name="submit1" value="1" />'; echo '<input type="submit" name="submit2" value="2" />'; echo '</form>'; ?> there are 2 buttons on the page . i want to when each button clicked , (after the first click) it disables itself + all other buttons AND the script run !! i've got this answers : one of answers: echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post" onSubmit="this.submit1.disabled = true;this.submit2.disabled = true;return true;">'; another one : echo '<input type="submit" name="submit1" value="1" onclick="this.disabled = true;return true;"/>'; echo '<input type="submit" name="submit2" value="2" onclick="this.disabled = true;return true;"/>'; another : echo '<input type="submit" name="submit1" value="1" onclick="this.disabled = true;"/>'; echo '<input type="submit" name="submit2" value="2" onclick="this.disabled = true;"/>'; none of them works fne , one disables but do not run script , one just reset script . another run script but do not disable buttons.!! thanks for your help Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted January 17, 2008 Share Posted January 17, 2008 <script language="javascript"> function send() { document.getElementById('submit1').disabled = true; document.getElementById('submit2').disabled = true; document.myForm.submit(); } </script> <form name="myForm" method="post"> <input type="button" id="submit1" onclick="send()" value="Submit"> <input type="button" id="submit2" onclick="send()" value="Submit"> </form> Quote Link to comment Share on other sites More sharing options...
asmith Posted January 18, 2008 Author Share Posted January 18, 2008 thanks phpquestioner, your code disables both button , but do not run the script . here is the last code i used : <?php if (isset($_POST[submit1])) { echo "111"; } elseif (isset($_POST[submit2])) { echo "222"; } ?> <script language="javascript"> function send() { document.getElementById('submit1').disabled = true; document.getElementById('submit2').disabled = true; document.myForm.submit(); } </script> <form name="myForm" method="post" action="java.php"> <input type="submit" name="submit1" onclick="send()" value="Submit1" id="submit1" /> <input type="submit" name="submit2" onclick="send()" value="Submit2" id="submit2" /> </form> Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted January 18, 2008 Share Posted January 18, 2008 I think when you disable the button; your disabling the value of the button too. If you were not submitting the page to itself; I don't think this would be a problem, but I think because you are submitting the page to itself - I believe that disabling the button does not allow it to receive the value of the button. Quote Link to comment Share on other sites More sharing options...
asmith Posted January 18, 2008 Author Share Posted January 18, 2008 i have so many pages that they would run themselves with 2 or 3 submit buttons. i don't have problem with the users who click a button so many times, i've deal with that with php code . but i am just so curious to see how can i disable after one click with java . still what good is a button which after the first click be disable but disable the value to ? what is good about it ? any solution i could do it with these type of pages ? (that run themselves with a few buttons) Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted January 18, 2008 Share Posted January 18, 2008 i have so many pages that they would run themselves with 2 or 3 submit buttons. i don't have problem with the users who click a button so many times, i've deal with that with php code . but i am just so curious to see how can i disable after one click with java . still what good is a button which after the first click be disable but disable the value to ? what is good about it ? any solution i could do it with these type of pages ? (that run themselves with a few buttons) form buttons were not really intended to send values anyway; they were create for actions, this is just a php coding technic. you would disable the button so the form is not submitted more then once to your php (which as I previously stated; if you had your php in another page, you would not have this problem). Quote Link to comment Share on other sites More sharing options...
asmith Posted January 19, 2008 Author Share Posted January 19, 2008 thanks for the information, at least i'm not hitting my head to wall to find its answer Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.