du_1993 2011-09-28 11:05
浏览 58

如何使用ajax,javascript和php更改多个表单元素

i am using ajax and javascript to change form element based on select option but i cant change only one text field, While i want to change multiple field e.g. selection on product i want to change its cost and stock value. here are my files -----------ajax file--------------

function loadXML(str)
    {
    if (str=="")
      {
      document.getElementById("mygDiv").innerHTML="";
      return;
      } 
    if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
      }
    else
      {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    xmlhttp.onreadystatechange=function()
      {
          if (xmlhttp.readyState==4 && xmlhttp.status==200)
          {
            document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
          }
      }
    xmlhttp.open("GET","price.php?q="+str,true);
    xmlhttp.send();
    }

-----------php file--------------

<?php   
include("connection.php");
@$m_id = $_GET['q'];    
$btn = mysql_query("select distinct batch_no from purchase_info where medicine_id ='$m_id' order by batch_no")or die(mysql_error());
    echo "<select name='batchno' >";
    if(mysql_num_rows($btn))
    {
        while($rows = mysql_fetch_array($btn))
        {
        ?>
            <option value="<?php echo $rows['batch_no'] ?>"><?php echo $rows['batch_no'] ?></option> <
    <?php   
        } 
    }?>
    </select>
  • 写回答

1条回答 默认 最新

  • doujia7094 2011-09-28 11:20
    关注

    You can use XML format for ajax calls. Using PHP, output XML file instead of HTML.

    This can be helpful If you don't know what I'm talking about. http://www.v7n.com/forums/coding-forum/45263-create-xml-file-using-php.html

    Then , in JavaScript, use xmlHttp.responseXML instead of responseHTML.

    You will get an XML DOM structure in JavaScript that you can parse. This can be helpful if you do not know how to parse XML document in JavaScript. http://www.adobepress.com/articles/article.asp?p=425820&seqNum=7

    The point is that you can have different XML nodes that represent different things. For example you could have a node

    <value>25</value>
    

    In Javascript, you read this node's text (25) and do something with it on the page - for example set value of some input field to 25.

    评论

报告相同问题?

悬赏问题

  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示