donglizuo8892 2013-03-30 07:36
浏览 16
已采纳

操作完成后禁用提交表单

Ok, I've been going nuts for hours trying to figure this out...

I want my form to be disabled after clicking it so multiple submissions don't occur. But when ever I try methods to disable it.. And I have tried MANY ways, It will disable the button after clicking it but it stops all the functions that form was supposed to do. for instance adding this to my code disables the form after clicking it but stops all functions.

onclick="this.disabled=true;this.value='Sending, please wait...';this.form.submit();"

Here is my form

<form name="input" action="" method="post" id="id">
  <div align="center">
    <input name="Submit" id="Submit" type="submit" class="button" value="Explore Map!"/>
  </div>
</form> 

Here is what is supposed to happen when the form is clicked ( I know the code is horrible and unsafe but it works and thats pretty much what I need.)

if (isset($_POST['Submit'])) {

include 'includes/mapstuff.php';

// Ok so we called the submit button sbubmit and the method is post so

// So here we pick a random row from the table pokemon notice the order by rand
$sql23 = "SELECT * FROM map1pokemon ORDER BY RAND() LIMIT 1;";
// We then check for errors
$result23 = mysql_query($sql23) or die(mysql_error());
// we then make the result into a virable called battle_get23
$battle_get23 = mysql_fetch_array($result23);

$sql2 = "SELECT * FROM pokemon WHERE name='".$battle_get23['pokemon']."'";
$result2 = mysql_query($sql2) or die(mysql_error());
$battle_get2 = mysql_fetch_array($result2);

// Now we need to make sure the image is safe be for we use it
$pic2= mysql_real_escape_string($battle_get2['pic']);
$pic = strip_tags($pic2);


include 'includes/maptypes.php';


?>


<form name="inputt" action="" method="post">
  <div align="center">
    <input type="submit" class="catch" value="Catch Pokemon" name="catch">
  </div>
</form> 
<p></p>

<?php
echo "You have just found a " ;
echo $randomview[0];
echo " ";

// we can now print off any column we want about the random pokemon e.g the name the pic etc... here I chose to print out the name.but th
echo $battle_get23['pokemon'];


$_SESSION['pokemon'] = $battle_get23['pokemon']; 
$_SESSION['type'] = $randomview[0];
$_SESSION['pic'] = $battle_get2;
$_SESSION['money'] = $randomview2[0];
$_SESSION['level'] = $randomview3[0];
$_SESSION['ticket'] = $randomview4;

?>
<p></p>
<?php
echo "You have gained ".$randomview3[0]." levels" ;
echo " ";
?>
<p></p>
<?php
echo "You have received $".$randomview2[0]."" ;
echo " ";
?>
<p></p>
<?php
echo "</center>";
}

?>
  • 写回答

2条回答 默认 最新

  • dongmi3203 2013-03-30 07:40
    关注

    Using Jquery

    $("form").submit(function() {
        $(this).submit(function() {
            return false;
        });
        return true;
    });
    

    Refer this Question

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决