Jump to content

[SOLVED] buttons grrr


asmith

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/86427-solved-buttons-grrr/
Share on other sites

<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>

Link to comment
https://forums.phpfreaks.com/topic/86427-solved-buttons-grrr/#findComment-442205
Share on other sites

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>

Link to comment
https://forums.phpfreaks.com/topic/86427-solved-buttons-grrr/#findComment-442574
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/86427-solved-buttons-grrr/#findComment-442606
Share on other sites

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)

Link to comment
https://forums.phpfreaks.com/topic/86427-solved-buttons-grrr/#findComment-442633
Share on other sites

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).

Link to comment
https://forums.phpfreaks.com/topic/86427-solved-buttons-grrr/#findComment-443071
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.