By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,780 Members | 1,520 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,780 IT Pros & Developers. It's quick & easy.

using <div> inside <form>

P: 7
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=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Your browser does not support AJAX!");
return;
}
var url="confirm.jsp";
url=url+"?q="+document.login.id.value;
//url=url+"&sid="+Math.random();
url=url+"&p="+document.login.pwd.value;
//url=url+"&pid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function stateChanged()
{
if (xmlHttp.readyState==4)
{
alert("hi");
//var message = xmlHttp.responseXML.getElementsByTagName("message" )[0].childNodes[0].data;
//alert(message);
alert("everone");
alert(xmlHttp.responseText);
var response=xmlHttp.responseText;
document.getElementById("hema").innerHTML=response ;
alert(xmlHttp.responseText);
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="confirm()"></p>
</div>

<div>
<p>For Registration Click Here&nbsp;&nbsp;<input type="button" value="Register" onclick="register()"></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
Jul 4 '07 #1
Share this Question
Share on Google+
10 Replies


100+
P: 201
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=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Your browser does not support AJAX!");
return;
}
var url="confirm.jsp";
url=url+"?q="+document.login.id.value;
//url=url+"&sid="+Math.random();
url=url+"&p="+document.login.pwd.value;
//url=url+"&pid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function stateChanged()
{
if (xmlHttp.readyState==4)
{
alert("hi");
//var message = xmlHttp.responseXML.getElementsByTagName("message" )[0].childNodes[0].data;
//alert(message);
alert("everone");
alert(xmlHttp.responseText);
var response=xmlHttp.responseText;
document.getElementById("hema").innerHTML=response ;
alert(xmlHttp.responseText);
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="confirm()"></p>
</div>

<div>
<p>For Registration Click Here&nbsp;&nbsp;<input type="button" value="Register" onclick="register()"></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=GetXmlHttpObject(); use following

var xmlHttp= false;

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

}

Try This One , your problem must be solved.
Jul 4 '07 #2

P: 7
Hi

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

var xmlHttp= false;

if (window.XMLHttpRequest)
{
xmlHttp= new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
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.jsp(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.readyState==4)
{
alert(xmlHttp.responseText);
var response=xmlHttp.responseHTML;
document.getElementById("hema").innerHTML=response ;
alert(xmlHttp.responseText);
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..
Jul 4 '07 #3

epots9
Expert 100+
P: 1,351
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.jsp(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.readyState==4)
{
alert(xmlHttp.responseText);
var response=xmlHttp.responseHTML;
document.getElementById("hema").innerHTML=response ;
alert(xmlHttp.responseText);
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:
Expand|Select|Wrap|Line Numbers
  1. function stateChanged() 
  2. if (xmlHttp.readyState==4)
  3. alert(xmlHttp.responseText);
  4. var response=xmlHttp.responseText; // u had responseHTML
  5. document.getElementById("hema").innerHTML=response;
  6. alert(xmlHttp.responseText);
  7. alert("Hi in state changed");
  8.  
  9. }
  10. }
  11.  
good luck
Jul 4 '07 #4

P: 7
try this:
Expand|Select|Wrap|Line Numbers
  1. function stateChanged() 
  2. if (xmlHttp.readyState==4)
  3. alert(xmlHttp.responseText);
  4. var response=xmlHttp.responseText; // u had responseHTML
  5. document.getElementById("hema").innerHTML=response;
  6. alert(xmlHttp.responseText);
  7. alert("Hi in state changed");
  8.  
  9. }
  10. }
  11.  

good luck

Yeah it worked fine, Thanks praveen2gupta and epots9..,
Jul 5 '07 #5

100+
P: 201
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=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Your browser does not support AJAX!");
return;
}
var url="confirm.jsp";
url=url+"?q="+document.login.id.value;
//url=url+"&sid="+Math.random();
url=url+"&p="+document.login.pwd.value;
//url=url+"&pid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function stateChanged()
{
if (xmlHttp.readyState==4)
{
alert("hi");
//var message = xmlHttp.responseXML.getElementsByTagName("message" )[0].childNodes[0].data;
//alert(message);
alert("everone");
alert(xmlHttp.responseText);
var response=xmlHttp.responseText;
document.getElementById("hema").innerHTML=response ;
alert(xmlHttp.responseText);
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="confirm()"></p>
</div>

<div>
<p>For Registration Click Here&nbsp;&nbsp;<input type="button" value="Register" onclick="register()"></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.readyState==4)

try following line

if (xmlHttp.readyState == 4 && xmlHttp.status == 200)

I think your problem may solve
Jul 5 '07 #6

P: 7
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=xmlHttp.responseText;
document.getElementById("hello").innerHTML=respons e;

<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..,Thanks...
Jul 5 '07 #7

acoder
Expert Mod 15k+
P: 16,027
I've merged the threads. If it's the same problem, keep it in one thread.
Jul 5 '07 #8

P: 7
Hi
in place of line
if (xmlHttp.readyState==4)

try following line

if (xmlHttp.readyState == 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??
Jul 5 '07 #9

100+
P: 201
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

Expand|Select|Wrap|Line Numbers
  1. <script language = "javascript">
  2. var HttpObj = false;
  3.     if (window.XMLHttpRequest) 
  4.     {
  5.         HttpObj = new XMLHttpRequest();
  6.     } 
  7.     else if (window.ActiveXObject) 
  8.     {
  9.         HttpObj = new ActiveXObject("Msxml2.XMLHTTP");
  10.  
  11.     }
  12. function getData()
  13.     {
  14.         if(HttpObj) 
  15.         {
  16.     HttpObj.open("GET", "Fw_Text7.jsp",true);
  17.     HttpObj.onreadystatechange = function()
  18.             {
  19.                 if (HttpObj.readyState == 4 && HttpObj.status == 200) 
  20.                 {
  21. document.getElementById("targetDiv").innerHTML = HttpObj.responseText;
  22.  
  23.                 }
  24.             }
  25.             HttpObj.send(null);
  26.         }
  27.     }
  28. </script>
  29. </head>
  30. <body>
  31. <H1>Fetching data with Ajax</H1>
  32. <form>
  33. <input type="button" value="Display Message" onmouseover='getData()'>
  34.  
  35. </form>
  36.  
  37. <div id="targetDiv">
  38. <p>The fetched data will go here.</p>
  39. </div>
  40. </body>
  41. </html>
  42.  

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
Jul 5 '07 #10

P: 7
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

Expand|Select|Wrap|Line Numbers
  1. <script language = "javascript">
  2. var HttpObj = false;
  3.     if (window.XMLHttpRequest) 
  4.     {
  5.         HttpObj = new XMLHttpRequest();
  6.     } 
  7.     else if (window.ActiveXObject) 
  8.     {
  9.         HttpObj = new ActiveXObject("Msxml2.XMLHTTP");
  10.  
  11.     }
  12. function getData()
  13.     {
  14.         if(HttpObj) 
  15.         {
  16.     HttpObj.open("GET", "Fw_Text7.jsp",true);
  17.     HttpObj.onreadystatechange = function()
  18.             {
  19.                 if (HttpObj.readyState == 4 && HttpObj.status == 200) 
  20.                 {
  21. document.getElementById("targetDiv").innerHTML = HttpObj.responseText;
  22.  
  23.                 }
  24.             }
  25.             HttpObj.send(null);
  26.         }
  27.     }
  28. </script>
  29. </head>
  30. <body>
  31. <H1>Fetching data with Ajax</H1>
  32. <form>
  33. <input type="button" value="Display Message" onmouseover='getData()'>
  34.  
  35. </form>
  36.  
  37. <div id="targetDiv">
  38. <p>The fetched data will go here.</p>
  39. </div>
  40. </body>
  41. </html>
  42.  

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...
Jul 6 '07 #11

Post your reply

Sign in to post your reply or Sign up for a free account.