dousuie2222 2016-03-11 14:23
浏览 88
已采纳

带有onchange的PHP JavaScript未被捕获错误[重复]

This question already has an answer here:

I have dropdown list and when somebody chooses something I need to submit it, here's my code:

<meta http-equiv="content-type" content="text/html; charset=UTF-8">
   <body bgcolor="#E2E2E2">
       <form action='index.php' method='post' enctype='multipart/form-data'    id='myform'>
     <div div style="position: absolute;left: 35%; top: 30%;">
    <link rel="stylesheet" type="text/css" href="CSS.css">
      <?php
     include ("config.php");
     // Create connection
  //form start

     if ($result->num_rows > 0) {


 // output data of each row
 echo"<tr><td>формат: ";

       echo"<select class='format' name='formater'onchange='document.getElementById('myform').submit()'>";
        while($row = $result->fetch_assoc()) {
      echo "<option value='". $row["$formatPrice"]. "'>".$row["$formatColumn"]. "</option>";
 }

  }
     if(isset($_POST['submit'])){
     echo "aaa";
  }
 ?>

When i choose option that error comes out: Uncaught TypeError: object is not a function onchange Thanks for any help.

Here is rendered html:

    <html><head><meta http-equiv="content-type" content="text/html; charset=UTF-8">
  </head><body bgcolor="#E2E2E2">
    <form action="client.php" method="post" enctype="multipart/form-data" id="myform">
     <div div="" style="position: absolute;left: 35%; top: 30%;">
   <link rel="stylesheet" type="text/css" href="CSS.css">
    <table border="1px" class="table"><tbody><tr><td>Calculator </td></tr>        <tr><td>ფორმატი: <select class="format" name="formater" onchange="document.getElementById(" myform').submit()'=""><option   value="0.15">A3</option><option value="0.1">A4</option><option value="0.05">A5</option><option value="0.035">A4/3</option>aaa</select></td>        </tr><tr><td><input type="submit" name="submit" class="btn" value="Submit"></td> </tr>


  </tbody></table></div></form></body></html>

So after marking this question as duplicate, Quentin showed me this link "Submit is not a function" error in JavaScript and yes, its absolutely another thing, these answers didn't help me, I think its more in PHP than in js, because i tried this code without PHP and it worked... Now I am becoming more confused with this!

</div>
  • 写回答

1条回答 默认 最新

  • duankuiyuant3940 2016-03-11 14:30
    关注

    I would give the form an ID to make it easier to identify it

    <form action='index.php' method='post' id='myform' enctype='multipart/form-data'>
    

    then use this for your onchange event

    onchange='document.getElementById("myform").submit()'
    

    I'm not sure if there is something with your formatting. Try...

    <form action="index.php" method="post" id="myform" enctype="multipart/form-data">
    <?php
    echo "<select class=\"format\" name=\"formater\" onchange=\"document.getElementById('myform').submit()\">";
    while($row = $result->fetch_assoc()) {
        echo "<option value=\"" . $row['$formatPrice'] . "\">" . $row['$formatColumn'] . "\"</option>";
    }
    ?>
    

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助