Javascript提交功能正常,无法正常工作

时间:2014-01-06 18:53:03

标签: javascript forms

我对此问题犹豫不决,因为它有点复杂,但我会尽量让它变得简单。

我有一个包含多个表单字段的页面。

我通过提交脚本提交页面(注意更多内容在此提交脚本中完成,但为了简单起见,我将其删除

 function do_file_form_submit(gonext) {
 var f = document.getElementById('file_form');
 f.gonext.value = gonext;
 alert(gonext);
 f.submit();
 }

请注意,此功能中还包含其他变量。 indxt并不是唯一一个,但在这种情况下,我将其他人留下来以保持简单。

为简单起见,我的HTML看起来像这样:

 <form name="file_form" id=file_form action="<?= $this->URL('#', 'UpdateUploadUser', array('mode'=>'upload', 'ID'=>$_GET['ID']));?>" method="post" enctype="multipart/form-data">
 <input type="text" name="oneitem">

 <button name="submit1"  id="submit1" onclick="do_file_form_submit(2);"><img src="<?=$theme;?>/images/12addphoto32px.png">Save Settings Then Upload/Register Another</button>

在“UpdateUploadUser”函​​数的后端,我们有一个检查器,它检查每个提交的字段以查看它是否为空。如果为空,则返回:

        $this->chk = new mVal($event);

                    if(!$this->chk->Validate()) {
            $this->mode = 'error_redisplay';
                            //$this->mode='Error';
                            return;
                    }

如果所有信息都存在,则脚本继续并按预期运行。所以,这是问题所在。

如果有所有信息,我点击按钮,那么一切正常。 file_form提交JS ALERTS的废弃值,脚本运行并按原样更新。

但是,如果缺少某个项目,则验证脚本将运行并“返回”。

一旦页面返回,如果你然后尝试单击提交按钮,页面STILL应该提交它,但file_form提交脚本看起来好像它甚至没有运行,所以passxt值不是通过了。

所以,我试图弄清楚除了这个do_file_form_submit脚本之外,表单的提交是如何发生的。是否有与“回归”有关的事情我不知道?

希望有意义并感谢任何帮助!

克雷格

1 个答案:

答案 0 :(得分:0)

查看您的代码

 function do_file_form_submit(gonext) {
     var f = document.getElementById('file_form');
     f.gonext.value = gonext;//f.gonext. i can not find gonext in ur form. just oneitem  try something like f.oneitem.value = gonext; i believe that is where the //problem occurs
     alert(gonext);
     f.submit();
     }

简而言之,更换一行:

f.gonext.value = gonext;

document.file_form.value = gonext;

然后像

一样提交
document.file_form.submit();
相关问题