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

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。