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.

    评论

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大