Loading data from database with php and pure ajax in a textbox

前端 未结 2 1087
感动是毒
感动是毒 2021-01-17 08:08

i have one dropdown list which has data for \"subjects\" loaded from database. when i clicked on one subject what it should do is load related \"subject_id\" value inside te

2条回答
  •  庸人自扰
    2021-01-17 08:35

    The mistake was done at ajax part document.getElementById("bookid").innerHTML and must be replaced with document.getElementById().value since I had to put data to Html Element that cotain value i.e Textbox(as textbox contain value attribute).

    InnerHTML is used to manipulate the html elements that does not contain value, ** div,h1, ** etc. for details see below link.

    http://www.verious.com/qa/what-39-s-the-difference-between-document-get-element-by-id-quot-test-quot-value-and-document-get-element-by-id-quot-tes/

    ajax code

      function show_bookid(str)
    {
        var xmlhttp;
        if(str.length==0)
        {
            document.getElementById("bookid").value="";
            return;
        }
        if(window.XMLHttpRequest)
        {
            xmlhttp= new XMLHttpRequest();
        }
        else
        {
            xmlhttp=new ActiveXOjbject("Microsoft.XMLHttpRequest"); 
        }
        xmlhttp.onreadystatechange=function()
        {
            if (xmlhttp.readyState==4 && xmlhttp.status==200)
            {
                document.getElementById("bookid").value=xmlhttp.responseText;
            }
        }
            xmlhttp.open("GET","getbook.php?q="+str,true);
            xmlhttp.send();
    
    }
    

    getbook.php

    
    

    addbook.php

                

提交回复
热议问题