Link to home
Start Free TrialLog in
Avatar of mrigank
mrigank

asked on

Refreshing part of a page

I have a requirement for which i have to go to the server , fetch some data and refresh only a part of the page. The rest of the page should remain as it is. I am thinking of using Frames. Any other way to do it ??

Thanks,
Mrigank.
Avatar of TimYates
TimYates
Flag of United Kingdom of Great Britain and Northern Ireland image

> Any other way to do it ??

Not that I can think of...  Why can't you refresh the whole page?
Avatar of mrigank
mrigank

ASKER

Actually if i refresh the whole page, i will have to save the state of the page... which i would not want to do .. as i do not want to make db calls....  Not sure if struts will do the same for me
ASKER CERTIFIED SOLUTION
Avatar of TimYates
TimYates
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You could use an iFrame for this, but be warned that it's going to knock your cross-browser compatability right out of the water.

What you do is place an iFrame somewhere on your page and give it the attribute [style="display:none"]. When you post to the server, set the name of the iFrame as your target. What you do then is have the server return a page of javascript to the browser inside the hidden iFrame. The script will then execute.

You can use DOM targetting in javascript to alter on-creen values provided that these values are within valid, named forms and each item that may be altered has a name.

For example, you could say have a hidden control variable change to the value 17, and have an onscreen select box change it's contents with the returned script below:

<script language="JavaScript">
  parent.theForm.controlVar.value = 17; //change value of hidden field
  parent.theForm.areaSelect.options.length = 0; //clear the previously held array of options

  //array of option names
  var options = new Array('option A', 'option B', 'option C');

  //array of option values
  var values = new Array('A','B','C');

  //grab a short handle on the select box
  var sBox = parent.theForm.areaSelect;
  for (i = 0; i < options.length; I++) {
    sBox.options[i] = new Option(options[i], values[i]);
  }
</script>

If you need more information about dynamic select boxes you can visit http://www.quirksmode.org/js/options.html.

Hope this helps.