dongmian5325
2013-08-28 05:58
浏览 49

提交按钮不响应操作

I have an odd problem !! my submit button not respond for action !!!

I have this code:

<script type="text/javascript">
    function save_contact_information() {

        document.getElementById('User_Finder').action = "Controler/controller_page.php?button=save_contact_information";

    }
</script>
<form id="User_Finder" action="User_Finder.php?ID_CV_User=<?php print $ID_CV_User ?>&&change_profile=ok"
method="post" enctype="multipart/form-data">

    <input type="submit" id="CI_BT_Save" onclick="save_contact_information()"
    name="BT_PI_Save" value="Save" style="position:absolute;left:12px;top:333px;width:96px;height:25px;z-index:342;">

</form>

if I click on the button save , nothing will be change !!! I change the code of the function 'save_contact_information()' as bellow:

function save_contact_information() {
    alert("ok1");
    document.getElementById('User_Finder').action = "Controler/controller_page.php?button=save_contact_information";
    alert("ok2");
}

Now if I Click on button save , 2 alerts will be visible : ok1 + ok2 but this line : document.getElementById('User_Finder').action ="Controler/controller_page.php?button=save_contact_information"; not given any reaction !!!

Have anyone any idea about this ODD problem !!!

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

5条回答 默认 最新

  • duancheng7743 2013-08-28 06:01
    已采纳
    function save_contact_information() {
    alert("ok1");
                    document.getElementById('User_Finder').action ="Controler/controller_page.php?button=save_contact_information";
    alert("ok2");
      document.getElementById('User_Finder').submit(); //here form submit with your action
    
    
                }
    
    点赞 评论
  • douxia3505 2013-08-28 06:00

    its a form so u have to add event.preventDefault()

    EDIT: Do this

    function save_contact_information() {
        alert("ok1");
    event.preventDefault();
        document.getElementById('User_Finder').action = "Controler/controller_page.php?button=save_contact_information";
        alert("ok2");
    document.getElementById('User_Finder').submit();
    }
    
    点赞 评论
  • douhu1990 2013-08-28 06:01

    document.getElementById("User_Finder").submit();

    点赞 评论
  • douwen5833 2013-08-28 06:04

    Change your function to:

    function save_contact_information() {
    var myForm = document.getElementById('User_Finder');
    myForm.action ="Controler/controller_page.php?button=save_contact_information";
    myForm.submit();
    }
    

    Details:

    Since your button is calling another function, the call to new action will only happen on the next click. You may also trigger the submit of the form again by manually calling the submit function.

    You may also want to declare myForm variable one off to avoid heavy DOM manipulations every-time you try to search for the form.

    点赞 评论
  • dse323222 2013-08-28 06:08

    Instead of on click for submit button use on submit in form tag with return. That is better approach. It will work.

    <form id="User_Finder" action="User_Finder.php?ID_CV_User=<?php print $ID_CV_User ?>&&change_profile=ok" method="post" onsubmit="return save_contact_information()" enctype="multipart/form-data">
    
       <input type="submit" id="CI_BT_Save" name="BT_PI_Save" value="Save" style="position:absolute;left:12px;top:333px;width:96px;height:25px;z-index:342;">
    
    </form>
    
    
    <script type="text/javascript">
    function save_contact_information() {
    
        document.getElementById('User_Finder').action = "Controler/controller_page.php?button=save_contact_information";
        return true;
    
    }
    </script>
    

    Try to avoid onclick event for submit button always

    点赞 评论

相关推荐 更多相似问题