dongrou839975 2015-07-09 23:44
浏览 37
已采纳

JavaScript Text不提交表单

I am working on my first web application and I am trying to use javascript to submit a form by clicking on text. When I click on the text nothing happens. It should just open to a simple webpage for now. I know how to process forms with html, but when I try and use javascript nothing happens. I am using unix and i have already configured my server and chmod 755 the cgi file. I not it is not a server error as I have executed cgi files on it before. I am following this tutorial: http://www.thesitewizard.com/archive/textsubmit.shtml

Here is my test 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>

And here is the cgi file:

#!/usr/bin/python

import cgitb, cgi
cgitb.enable()

print "Content-type:text/html

"
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>'

I am at a complete loss with what is wrong as I do not have much experience with javascript. Any help is appreciated!

  • 写回答

1条回答 默认 最新

  • dongliyan7318 2015-07-10 00:02
    关注

    You cannot nest a <script>element inside <style>, the only allowed content is CSS. See e.g. the MDN docs.

    Move <script> to either <head> or <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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路