JavaScript文字未提交表单

时间:2015-07-09 23:44:52

标签: javascript php jquery html forms

我正在处理我的第一个Web应用程序,我正在尝试使用javascript通过单击文本来提交表单。当我点击文本时没有任何反应。它现在应该只对一个简单的网页开放。我知道如何使用html处理表单,但是当我尝试使用javascript时没有任何反应。我正在使用unix,我已经配置了我的服务器和chmod 755 cgi文件。我不是它不是服务器错误,因为我之前已经执行过cgi文件。我正在关注本教程: http://www.thesitewizard.com/archive/textsubmit.shtml

这是我的测试html:

<html>
<head>
    <title>EDVT Report Generator</title>
    <style>
        h1 {
            text-align: center;
        }
        <script language="JavaScript" type="text/javascript">

            function getsupport ( selectedtype )
            {
              document.supportform.supporttype.value = selectedtype ;
              document.supportform.submit() ;
            }

        </script>
    </style>
</head>
<body>
    <h1 id = "title">Test</h1>
    <form name="supportform" method="post" action="/cgi-bin/hello.py">
        <input type="hidden" name="supporttype" />
        <a href="javascript:getsupport('Paid')" onclick = "getsupport('Paid')">Paid Support</a> or
        <a href="javascript:getsupport('Free')" onclick = "getsupport('Free')">Free Support</a>
    </form>
</body>
</html>

这是cgi文件:

#!/usr/bin/python

import cgitb, cgi
cgitb.enable()

print "Content-type:text/html\r\n\r\n"
print '<html>'
print '<head>'
print '<title>Hello Word - First CGI Program</title>'
print '</head>'
print '<body>'
print '<h2>Hello Word! This is my first CGI program</h2>'
print '</body>'
print '</html>'

由于我对javascript没有多少经验,我完全失去了我的错误。任何帮助表示赞赏!

1 个答案:

答案 0 :(得分:0)

您无法在<script>内嵌套<style>元素,唯一允许的内容是CSS。参见例如the MDN docs

<script>移至<head><body>

<html>
<head>
    <title>EDVT Report Generator</title>
    <style>
        h1 {
            text-align: center;
        }
    </style>
</head>
<body>
    <script language="JavaScript" type="text/javascript">

            function getsupport ( selectedtype )
            {
              document.supportform.supporttype.value = selectedtype ;
              document.supportform.submit() ;
            }

     </script>
    <h1 id = "title">Test</h1>
    <form name="supportform" method="post" action="/cgi-bin/hello.py">
        <input type="hidden" name="supporttype" />
        <a href="javascript:getsupport('Paid')" onclick = "getsupport('Paid')">Paid Support</a> or
        <a href="javascript:getsupport('Free')" onclick = "getsupport('Free')">Free Support</a>
    </form>
</body>
</html>
相关问题