Javascript 表单提交第一次失败,并在刷新页面后生效

Javascript 表单提交第一次失败,并在刷新页面后生效,javascript,html,django,form-submit,Javascript,Html,Django,Form Submit,我正在运行一个django web应用程序,当我第一次提交表单失败时,我需要刷新并再次提交表单,以便在其中发送数据,或者在web浏览器上执行反向操作。 我正在使用javascript程序(editarea)在文本区域上自动着色代码 这是我的HTML文件: <html> <head> <title>Test</title> <script language="javascript" type="text/javascript"

我正在运行一个django web应用程序,当我第一次提交表单失败时,我需要刷新并再次提交表单,以便在其中发送数据,或者在web浏览器上执行反向操作。 我正在使用javascript程序(editarea)在文本区域上自动着色代码

这是我的HTML文件:

<html>
<head>
    <title>Test</title>
    <script language="javascript" type="text/javascript" src="/static/edit_area/edit_area_full.js"></script>
    <script type="text/javascript">
        function load() {
            var combo = document.getElementById('selSeaShells1').value;
            editAreaLoader.init({
                id: "textarea_1"        // textarea id
                    , syntax: combo                // syntax to be uses for highgliting
                    , start_highlight: true     // to display with highlight mode on start-up
            });
        }
    </script>
</head>
<body onload="load();">
    <form id="codeid" method="post" enctype="application/x-www-form-urlencoded" name="code" action="DestinationAddress/function">
    <h3>Choose a language</h3>
    <select name="sellang1" id="selSeaShells1" onchange="load();">
        <option value="python">Python</option>
        <option value="perl">Perl</option>
        <option value="sql">SQL</option>
        <option value="cpp">C++</option>
        <option value="c">C</option>
        <option value="java">Java</option>
        <option value="css">Css</option>
    </select>
    <br>
    <textarea id="textarea_1" name="content" cols="80" rows="15" type="text"></textarea>
    <input id="thebutton" type="button" value="Submit" onclick="document.forms.codeid.submit();" />
    </form>
</body>
</html>

你的javascript失败了
var combo=document.getElementById('selSeaShells1')。值;
Combo将是未定义的,因为您正在页面完成加载之前调用load()。
我将使用jquery并执行以下操作:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> //download and get a local copy of jquery don't use googles.***<script>

$(document).ready(function() {
    load();
});

function load()
    {     
        var combo = $('#selSeaShells1 option:selected).val();

            editAreaLoader.init({
            id : "textarea_1"       // textarea id
            ,syntax: combo                // syntax to be uses for highgliting
            ,start_highlight: true      // to display with highlight mode on start-up
            });


    }

</script>
//下载并获取jquery的本地副本不要使用谷歌***
$(文档).ready(函数(){
加载();
});
函数加载()
{     
var combo=$('#selSeaShells1选项:选中).val();
editAreaLoader.init({
id:“textarea_1”//textarea id
,syntax:combo//用于高速滑行的语法
,start_highlight:true//在启动时以突出显示模式显示
});
}
删除body标签上的onload=“load();”

这将在页面加载后获得选择

当它失败时,实际会发生什么?是否有错误消息?您是否在javascript控制台打开的情况下尝试过它?您的视图是否实际在同一站点中调用URL?若然,原因为何?
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> //download and get a local copy of jquery don't use googles.***<script>

$(document).ready(function() {
    load();
});

function load()
    {     
        var combo = $('#selSeaShells1 option:selected).val();

            editAreaLoader.init({
            id : "textarea_1"       // textarea id
            ,syntax: combo                // syntax to be uses for highgliting
            ,start_highlight: true      // to display with highlight mode on start-up
            });


    }

</script>