如何使用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个回答

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.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐