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

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?