using <div> inside <form>

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • neverquit
    New Member
    • Jul 2007
    • 7

    using <div> inside <form>

    hi ,
    Iam Nagesh,Begineer in using Ajax,well

    i have been using ajax in application, i have faced a problem while placing the responseTEXT into the <div> tag positioned inside the <form> tag
    iam able to get the response in the <div> tag in mozilla (im takingthe HTML response),
    <script>
    function confirm()
    {
    xmlHttp=GetXmlH ttpObject();
    if (xmlHttp==null)
    {
    alert ("Your browser does not support AJAX!");
    return;
    }
    var url="confirm.js p";
    url=url+"?q="+d ocument.login.i d.value;
    //url=url+"&sid=" +Math.random();
    url=url+"&p="+d ocument.login.p wd.value;
    //url=url+"&pid=" +Math.random();
    xmlHttp.onready statechange=sta teChanged;
    xmlHttp.open("G ET",url,true) ;
    xmlHttp.send(nu ll);
    }

    function stateChanged()
    {
    if (xmlHttp.readyS tate==4)
    {
    alert("hi");
    //var message = xmlHttp.respons eXML.getElement sByTagName("mes sage")[0].childNodes[0].data;
    //alert(message);
    alert("everone" );
    alert(xmlHttp.r esponseText);
    var response=xmlHtt p.responseText;
    document.getEle mentById("hema" ).innerHTML=res ponse;
    alert(xmlHttp.r esponseText);
    alert("Hi in state changed");

    }
    <script>

    and the form iam using in the <body> is

    <form name="login">

    <table align="center" >
    <tr>
    <td><b>UserId :</b></td>
    <td><input type="text" name="id"></td>
    </tr>
    <tr>
    <td><b>Password </b></td>
    <td><input type="password" name="pwd"></td>
    </tr>
    </table>
    <div align="center">
    <p><input type="button" value="Login" onclick="confir m()"></p>
    </div>

    <div>
    <p>For Registration Click Here&nbsp;&nbsp ;<input type="button" value="Register " onclick="regist er()"></p>
    </div>
    <div id="hema"></div>
    </form>


    so the issue is that i will get the html response in the script that should be displayed in the <div id="hema"> tag.

    It is working in mozilla but not in IE, any answers.., thanks
  • praveen2gupta
    New Member
    • May 2007
    • 200

    #2
    Originally posted by neverquit
    hi ,
    Iam Nagesh,Begineer in using Ajax,well

    i have been using ajax in application, i have faced a problem while placing the responseTEXT into the <div> tag positioned inside the <form> tag
    iam able to get the response in the <div> tag in mozilla (im takingthe HTML response),
    <script>
    function confirm()
    {
    xmlHttp=GetXmlH ttpObject();
    if (xmlHttp==null)
    {
    alert ("Your browser does not support AJAX!");
    return;
    }
    var url="confirm.js p";
    url=url+"?q="+d ocument.login.i d.value;
    //url=url+"&sid=" +Math.random();
    url=url+"&p="+d ocument.login.p wd.value;
    //url=url+"&pid=" +Math.random();
    xmlHttp.onready statechange=sta teChanged;
    xmlHttp.open("G ET",url,true) ;
    xmlHttp.send(nu ll);
    }

    function stateChanged()
    {
    if (xmlHttp.readyS tate==4)
    {
    alert("hi");
    //var message = xmlHttp.respons eXML.getElement sByTagName("mes sage")[0].childNodes[0].data;
    //alert(message);
    alert("everone" );
    alert(xmlHttp.r esponseText);
    var response=xmlHtt p.responseText;
    document.getEle mentById("hema" ).innerHTML=res ponse;
    alert(xmlHttp.r esponseText);
    alert("Hi in state changed");

    }
    <script>

    and the form iam using in the <body> is

    <form name="login">

    <table align="center" >
    <tr>
    <td><b>UserId :</b></td>
    <td><input type="text" name="id"></td>
    </tr>
    <tr>
    <td><b>Password </b></td>
    <td><input type="password" name="pwd"></td>
    </tr>
    </table>
    <div align="center">
    <p><input type="button" value="Login" onclick="confir m()"></p>
    </div>

    <div>
    <p>For Registration Click Here&nbsp;&nbsp ;<input type="button" value="Register " onclick="regist er()"></p>
    </div>
    <div id="hema"></div>
    </form>


    so the issue is that i will get the html response in the script that should be displayed in the <div id="hema"> tag.

    It is working in mozilla but not in IE, any answers.., thanks

    Hi

    You are using only one Object which is not supported By IE. after
    Line instead of this xmlHttp=GetXmlH ttpObject(); use following

    var xmlHttp= false;

    if (window.XMLHttp Request)
    {
    xmlHttp= new XMLHttpRequest( );
    }
    else if (window.ActiveX Object)
    {
    xmlHttp= new ActiveXObject(" Msxml2.XMLHTTP" );

    }

    Try This One , your problem must be solved.

    Comment

    • neverquit
      New Member
      • Jul 2007
      • 7

      #3
      Originally posted by praveen2gupta
      Hi

      You are using only one Object which is not supported By IE. after
      Line instead of this xmlHttp=GetXmlH ttpObject(); use following

      var xmlHttp= false;

      if (window.XMLHttp Request)
      {
      xmlHttp= new XMLHttpRequest( );
      }
      else if (window.ActiveX Object)
      {
      xmlHttp= new ActiveXObject(" Msxml2.XMLHTTP" );

      }

      Try This One , your problem must be solved.



      Thanks for ur reply,

      well it didnt solve my problem ,the thing is i need to put the HTML page response in the <div> tag with id="hema",i need to get the html page from registration.js p(this is the page to which im sending url and geting the response),where as i m getting it to be "undefined" after changing the code as u have suggested.in both mozilla n IE.,

      iam posting the function named stateChanged(): ::
      function stateChanged()
      {
      if (xmlHttp.readyS tate==4)
      {
      alert(xmlHttp.r esponseText);
      var response=xmlHtt p.responseHTML;
      document.getEle mentById("hema" ).innerHTML=res ponse;
      alert(xmlHttp.r esponseText);
      alert("Hi in state changed");

      }
      }

      im able to get the html content with tags int he var response in the above function but im unable to put the html into the div as mentioned befor,what is the possible way in which i can display the html content in the response as the
      html page inside the <div id="hema">,
      waiting 4 suggestion..
      thanq..

      Comment

      • epots9
        Recognized Expert Top Contributor
        • May 2007
        • 1352

        #4
        Originally posted by neverquit
        Thanks for ur reply,

        well it didnt solve my problem ,the thing is i need to put the HTML page response in the <div> tag with id="hema",i need to get the html page from registration.js p(this is the page to which im sending url and geting the response),where as i m getting it to be "undefined" after changing the code as u have suggested.in both mozilla n IE.,

        iam posting the function named stateChanged(): ::
        function stateChanged()
        {
        if (xmlHttp.readyS tate==4)
        {
        alert(xmlHttp.r esponseText);
        var response=xmlHtt p.responseHTML;
        document.getEle mentById("hema" ).innerHTML=res ponse;
        alert(xmlHttp.r esponseText);
        alert("Hi in state changed");

        }
        }

        im able to get the html content with tags int he var response in the above function but im unable to put the html into the div as mentioned befor,what is the possible way in which i can display the html content in the response as the
        html page inside the <div id="hema">,
        waiting 4 suggestion..
        thanq..
        try this:
        [CODE=javascript]
        function stateChanged()
        {
        if (xmlHttp.readyS tate==4)
        {
        alert(xmlHttp.r esponseText);
        var response=xmlHtt p.responseText; // u had responseHTML
        document.getEle mentById("hema" ).innerHTML=res ponse;
        alert(xmlHttp.r esponseText);
        alert("Hi in state changed");

        }
        }
        [/CODE]

        good luck

        Comment

        • neverquit
          New Member
          • Jul 2007
          • 7

          #5
          Originally posted by epots9
          try this:
          [CODE=javascript]
          function stateChanged()
          {
          if (xmlHttp.readyS tate==4)
          {
          alert(xmlHttp.r esponseText);
          var response=xmlHtt p.responseText; // u had responseHTML
          document.getEle mentById("hema" ).innerHTML=res ponse;
          alert(xmlHttp.r esponseText);
          alert("Hi in state changed");

          }
          }
          [/CODE]


          good luck

          Yeah it worked fine, Thanks praveen2gupta and epots9..,

          Comment

          • praveen2gupta
            New Member
            • May 2007
            • 200

            #6
            Originally posted by neverquit
            hi ,
            Iam Nagesh,Begineer in using Ajax,well

            i have been using ajax in application, i have faced a problem while placing the responseTEXT into the <div> tag positioned inside the <form> tag
            iam able to get the response in the <div> tag in mozilla (im takingthe HTML response),
            <script>
            function confirm()
            {
            xmlHttp=GetXmlH ttpObject();
            if (xmlHttp==null)
            {
            alert ("Your browser does not support AJAX!");
            return;
            }
            var url="confirm.js p";
            url=url+"?q="+d ocument.login.i d.value;
            //url=url+"&sid=" +Math.random();
            url=url+"&p="+d ocument.login.p wd.value;
            //url=url+"&pid=" +Math.random();
            xmlHttp.onready statechange=sta teChanged;
            xmlHttp.open("G ET",url,true) ;
            xmlHttp.send(nu ll);
            }

            function stateChanged()
            {
            if (xmlHttp.readyS tate==4)
            {
            alert("hi");
            //var message = xmlHttp.respons eXML.getElement sByTagName("mes sage")[0].childNodes[0].data;
            //alert(message);
            alert("everone" );
            alert(xmlHttp.r esponseText);
            var response=xmlHtt p.responseText;
            document.getEle mentById("hema" ).innerHTML=res ponse;
            alert(xmlHttp.r esponseText);
            alert("Hi in state changed");

            }
            <script>

            and the form iam using in the <body> is

            <form name="login">

            <table align="center" >
            <tr>
            <td><b>UserId :</b></td>
            <td><input type="text" name="id"></td>
            </tr>
            <tr>
            <td><b>Password </b></td>
            <td><input type="password" name="pwd"></td>
            </tr>
            </table>
            <div align="center">
            <p><input type="button" value="Login" onclick="confir m()"></p>
            </div>

            <div>
            <p>For Registration Click Here&nbsp;&nbsp ;<input type="button" value="Register " onclick="regist er()"></p>
            </div>
            <div id="hema"></div>
            </form>


            so the issue is that i will get the html response in the script that should be displayed in the <div id="hema"> tag.

            It is working in mozilla but not in IE, any answers.., thanks

            Hi
            in place of line
            if (xmlHttp.readyS tate==4)

            try following line

            if (xmlHttp.readyS tate == 4 && xmlHttp.status == 200)

            I think your problem may solve

            Comment

            • neverquit
              New Member
              • Jul 2007
              • 7

              #7
              &lt;div&gt; inside &lt;form&gt;

              HI, im using the below code, where iam dispalying the HTML in the div tag named "hello" which is inside the <form>
              code inside the function statedChanged()
              var response=xmlHtt p.responseText;
              document.getEle mentById("hello ").innerHTML=re sponse;

              <body>
              <form>
              <div id="hello">
              </div>
              </body>


              Iam able to view the html page in the div tag in mozilla,but iam unable to view it in IE, any suggestions are invited..,Thank s...

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                I've merged the threads. If it's the same problem, keep it in one thread.

                Comment

                • neverquit
                  New Member
                  • Jul 2007
                  • 7

                  #9
                  Originally posted by praveen2gupta
                  Hi
                  in place of line
                  if (xmlHttp.readyS tate==4)

                  try following line

                  if (xmlHttp.readyS tate == 4 && xmlHttp.status == 200)

                  I think your problem may solve

                  i did that but no use, its the same problem, it is giving, "Unknown Run time Error" in the script, unable unable to put response html page in the <div> tag located inside <form> tag..,any other ways??

                  Comment

                  • praveen2gupta
                    New Member
                    • May 2007
                    • 200

                    #10
                    Originally posted by neverquit
                    i did that but no use, its the same problem, it is giving, "Unknown Run time Error" in the script, unable unable to put response html page in the <div> tag located inside <form> tag..,any other ways??

                    Hi

                    you are using two functions in the javascript. I am enclosing an sample code using one function. Try to fit in your code. This is tested sample program

                    Code:
                    <script language = "javascript">
                    var HttpObj = false;
                    	if (window.XMLHttpRequest) 
                    	{
                    		HttpObj = new XMLHttpRequest();
                    	} 
                    	else if (window.ActiveXObject) 
                    	{
                    		HttpObj = new ActiveXObject("Msxml2.XMLHTTP");
                    
                    	}
                    function getData()
                    	{
                    		if(HttpObj) 
                    		{
                    	HttpObj.open("GET", "Fw_Text7.jsp",true);
                    	HttpObj.onreadystatechange = function()
                    			{
                    				if (HttpObj.readyState == 4 && HttpObj.status == 200) 
                    				{
                    document.getElementById("targetDiv").innerHTML = HttpObj.responseText;
                    		
                    				}
                    			}
                    			HttpObj.send(null);
                    		}
                    	}
                    </script>
                    </head>
                    <body>
                    <H1>Fetching data with Ajax</H1>
                    <form>
                    <input type="button" value="Display Message" onmouseover='getData()'>
                    
                    </form>
                    
                    <div id="targetDiv">
                    <p>The fetched data will go here.</p>
                    </div>
                    </body>
                    </html>

                    when mouse is moved over. function getData is called and file Fw_Text7.jsp is called by server and page Response is placed in the div named "targetDiv"
                    .complete code is on one page using one function. Adjust as per your needs of program

                    Comment

                    • neverquit
                      New Member
                      • Jul 2007
                      • 7

                      #11
                      Originally posted by praveen2gupta
                      Hi

                      you are using two functions in the javascript. I am enclosing an sample code using one function. Try to fit in your code. This is tested sample program

                      Code:
                      <script language = "javascript">
                      var HttpObj = false;
                      	if (window.XMLHttpRequest) 
                      	{
                      		HttpObj = new XMLHttpRequest();
                      	} 
                      	else if (window.ActiveXObject) 
                      	{
                      		HttpObj = new ActiveXObject("Msxml2.XMLHTTP");
                      
                      	}
                      function getData()
                      	{
                      		if(HttpObj) 
                      		{
                      	HttpObj.open("GET", "Fw_Text7.jsp",true);
                      	HttpObj.onreadystatechange = function()
                      			{
                      				if (HttpObj.readyState == 4 && HttpObj.status == 200) 
                      				{
                      document.getElementById("targetDiv").innerHTML = HttpObj.responseText;
                      		
                      				}
                      			}
                      			HttpObj.send(null);
                      		}
                      	}
                      </script>
                      </head>
                      <body>
                      <H1>Fetching data with Ajax</H1>
                      <form>
                      <input type="button" value="Display Message" onmouseover='getData()'>
                      
                      </form>
                      
                      <div id="targetDiv">
                      <p>The fetched data will go here.</p>
                      </div>
                      </body>
                      </html>

                      when mouse is moved over. function getData is called and file Fw_Text7.jsp is called by server and page Response is placed in the div named "targetDiv"
                      .complete code is on one page using one function. Adjust as per your needs of program

                      yeah it worked out, i made a mistake ,where im requesting to the jsp in which the fileds are in <form> tag and iam trying to put the response in the <form> tag agian, ie(indirectly im putting <form> inside another <form>)which is not suported in IE,ths the mistake i have ,done ,thankyou for ur help guyz...

                      Comment

                      Working...