Dynamic display of data to div in Struts with ajax
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Dynamic display of data to div in Struts with ajax

  1. #1
    Join Date
    Oct 2007
    Posts
    2

    Dynamic display of data to div in Struts with ajax

    I am developing an application in struts framework , where i am trying to display some content to the div tag in jsp when a option is selected in drop down box in a <html:form>

    i can do this in jsp using onchange=this.form.submit() but i dont want to use this method as it effects the performance of the page display,

    So i want to know is there is any other process to develop it

    Can any one tell me how to use ajax for this application

    Please provide me the information,

    Thanks in advance

  2. #2
    PeejAvery's Avatar
    PeejAvery is offline Super Moderator Power Poster
    Join Date
    May 2002
    Posts
    10,870

    Re: Dynamic display of data to div in Struts with ajax

    Well, AJAX is s true implementation of JavaScript. The JSP will come into play when you output the server-side code. Sometime like the follow should help you out!

    Code:
    <script type="text/javascript">
    function chkDropDown(obj, url){
      var xmlHTTP;
      try{xmlHTTP = new XMLHttpRequest();}
      catch(e){
        try{xmlHTTP = new ActiveXObject("Msxml2.XMLHTTP");}
        catch(e){
          try{xmlHTTP = new ActiveXObject("Microsoft.XMLHTTP");}
          catch(e){
            alert("Your browser does not support AJAX!");
            return false;
          }
        }
      }
    
      xmlHTTP.open('GET', url, true);
      xmlHTTP.send(null);
      xmlHTTP.onreadystatechange = function(){
        if(xmlHTTP.readyState == 4){
          populateList(obj, xmlHTTP.responseText);
        }
      }
    }
    
    function popuplateList(obj, results){
      obj.length = 0;
      var theOptions = results.split(',');
      for(i = 0; i < theOptions.length; i++) {
        obj.options[i] = new Option(theOptions[i], theOptions[i]);
      }
    }
    </script>
    
    <select name="whatever" onchange="chkDropDown(this, 'path/to/file.jsp')">
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center