开发者

firefox issues in document.forms[0].submit()

开发者 https://www.devze.com 2023-04-11 04:02 出处:网络
I have a form which I want to submit on bodyLoad. I have written document.forms[0].submit() which works fine with IE 9 and Chrome 14 but same is not working in FF 3.6.23.

I have a form which I want to submit on bodyLoad.

I have written document.forms[0].submit() which works fine with IE 9 and Chrome 14 but same is not working in FF 3.6.23.

Any ideas? Is this a known issue with FF?

I have tried other options like document.form_name.submit() and document.getElementById('form_id').submit() but nothing works with FF.

The error I am getting in FF is

document.forms[0] is undefined

This is what I have written in the view (CakePHP 1.2.6):

<?php $this->layout = 'blank'; ?>

<?php e($form->create('Mymodel', array('name'=>'myform', 'url'=>'gohere'))); ?>

<?php e($form->hidden('name', array('value'=>$name))); ?>

<?php e($form->end()); ?>

<script language="javascript">
doc开发者_StackOverflowument.forms[0].submit();
</script>


That won't work in Firefox, since the page isn't fully loaded yet.

Eliminate

document.forms[0].submit();

and set

<body onLoad="document.forms[0].submit();">

Be careful not to point <form> to the current page, as it would cause an endless loop.


The javascript code may be executed before the form is actually loaded. That's why Firefox can't find document.forms[0]. You have to make sure your page is ready before executing javascript. With JQuery, you do it with $(document).ready()

0

精彩评论

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

关注公众号