Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1

Thread: getElementById

  1. #1
    New Coder
    Join Date
    Oct 2007
    Posts
    19
    Thanks
    1
    Thanked 0 Times in 0 Posts

    getElementById

    In my form i have employee Id and grade.

    When i type the employee id , if the id is already in database then it will be displayed near to employee id text box

    When i select grade then all the grade above i selected should be displayed in next row of the table next to reporting to row...


    for employee id

    out.println("<TD><input type=\"Text\" name=\"empID\" value=\""+""+"\" onkeyup=\"showID(this.value)\"><span id=\"empid1\"></span></TD>");

    <script src="newemp.js"></script>


    Code:
    Code:
    var xmlHttp
    
    function showID(str)
    {
    if (str.length==0)
      { 
      document.getElementById("empid1").innerHTML="";
      return;
      }
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)
      {
      alert ("Your browser does not support AJAX!");
      return;
      } 
    var url="getID.jsp";
    url=url+"?q="+str;
    url=url+"&sid="+Math.random();
    xmlHttp.onreadystatechange=stateChanged;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
    } 
    
    function stateChanged() 
    { 
    if (xmlHttp.readyState==4)
    { 
    document.getElementById("empid1").innerHTML=xmlHttp.responseText;
    }
    }
    
    function GetXmlHttpObject()
    {
    var xmlHttp=null;
    try
      {
      // Firefox, Opera 8.0+, Safari
      xmlHttp=new XMLHttpRequest();
      }
    catch (e)
      {
      // Internet Explorer
      try
        {
        xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
      catch (e)
        {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
      }
    return xmlHttp;
    }
    For the grade drop down box
    out.println("<div id=\"txtGrading\"></div>"); here i want to disply the drop down box

    <div id="txtGrading"></div>

    out.println("<Select name=\"staff_grade\" onchange=\"showHintGrade(this.value)\" >");calling side

    <script type="text/javascript" src="grading.js"></script>

    grading.js


    Code:
    Code:
    var xmlHttp
    var s = new Array(50);
    function showHintGrade(str)
    {
    if (str.length==0)
      { 
      document.getElementById("txtGrading").innerHTML="";
      return;
      }
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)
      {
      alert ("Your browser does not support AJAX!");
      return;
      } 
    var url="GetHint1.jsp";
    url=url+"?q="+str;
    xmlHttp.onreadystatechange=stateChanged;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
    } 
    
    function stateChanged() 
    { 
    if (xmlHttp.readyState==4)
    { 
    document.getElementById("txtGrading").innerHTML=xmlHttp.responseText;
    }
    }
    function GetXmlHttpObject()
    {
    var xmlHttp=null;
    try
      {
      // Firefox, Opera 8.0+, Safari
      xmlHttp=new XMLHttpRequest();
      }
    catch (e)
      {
      // Internet Explorer
      try
        {
        xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
      catch (e)
        {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
      }
    return xmlHttp;
    }I don't have much idea

    please help
    Last edited by priyapratheep; 05-15-2008 at 07:20 AM. Reason: code formating


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •