开发者

window.onload not working to submit a for automatically

Can you tell why my form is not submitted automatically ?

<form action="../../../socialnetwork/index.php" method="post" name="hid" id="hid">
    <input type="hidden" name="UM_email" value="<?php echo $user_data->email; ?>" />
    <input type="hidden" name="provider" value="<?php echo $provider_adapter->user()->providerId; ?>" />
    <input type="submit" name="submit"/>
</form>

<script type="text/javascript">
function myfunc () {
//alert("loading....") its working
    var frm = document.getElementById("hid");
    frm.submit();
}
wind开发者_Go百科ow.onload = myfunc;
</script>


that is caused by the <input type="submit" name="submit" button.. change name to something like this name="button_submit" and it will work


Is something else overriding the window.onload property? A better way to achieve the same would be this:

if (window.addEventListener) {
  window.addEventListener('load', myfunc, false);
} else {
  window.attachEvent('onload', myfunc);
}

If you don't need to support IE less than version 9, you can skip the whole if/else and just use addEventListener directly.

Also, you may want to just use a javascript library to set the handler, that way browser differences are abstracted out (you don't have to worry about them).


Try changing name="button_submit" instead of name="submit" in input type.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜