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>";
    }
    ?>
    

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题