Forum Moderators: open

Message Too Old, No Replies

Ajax - How to Print <p> or Other HTML Elements?

Insted of a Form Text Box....

         

webgaya

9:39 am on Jul 1, 2007 (gmt 0)

10+ Year Member



In all Ajax tutorials I found, the server response is
printed on a form text box as below,

document.formName.textBoxName.value = ajaxRequest.responseText;

But my server response is not just a piece of text.
It contains few paragraphs and a form. How can I print
them right below where the Ajax was called?

For an example I want to print following set of HTML,

<p>first paragraph</p>

<form name="myForm">
<input type="text" name="fName">
<input type="button" name="submit" value="Submit">
</form>

<p>second paragraph</p>

daveVk

10:28 am on Jul 1, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Instead of putting response in text, place it within a div or other block element.

<div id="responseDiv"></div> // in place of text box

var divEl = document.getElementById("responseDiv");
divEl.innerHTML = ajaxRequest.responseText;

webgaya

2:46 pm on Jul 1, 2007 (gmt 0)

10+ Year Member



Hi,

I got it done. Thanks for your help!

webgaya

3:43 pm on Jul 1, 2007 (gmt 0)

10+ Year Member



Hi daveVk,

One more thing...

Can I bring the content in this div tag to the top of the page?
I mean this div is called at the bottom of the page and when the
Ajax is executed I want it to scroll automatically and come to
the div tag just like when we click a name link (<a name=>).

Is there a JavaScript property I can set to get this done?

Thanks...

daveVk

1:03 am on Jul 2, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try this, not 100% sure. May result in extra unwanted history entry.

document.location = "#anchor";

Place this in front of div

<a name="anchor"></a>

location.replace("#anchor") may be better alternative

webgaya

11:52 am on Jul 4, 2007 (gmt 0)

10+ Year Member



Hi daveVk,

Both work. I used the latter as you suggested.

Thanks again!