www.webdeveloper.com
Results 1 to 6 of 6

Thread: Execute a script and show results in the same page that called it

Hybrid View

  1. #1
    Join Date
    Jan 2013
    Posts
    84

    Question Execute a script and show results in the same page that called it

    I've created a simple form that allow to insert a word and search it into a database

    PHP Code:
    <form method="post" action="cerca_ragione_sociale.asp">
     <
    label>Inserisci ragione sociale</label>
       <
    input name="chiave"/>
      <
    label
      
      <
    input type="submit"/>
    </
    form
    the problem is that the result is opened into a new page, while i want to show it in the same page of the form

    I want to precise that i can do it throught javascript, but what i want to know if is it possibile to do it simple changing come parameter of the submit button.

  2. #2
    Join Date
    Mar 2011
    Posts
    1,139
    No, HTML cannot do that by itself. It requires either JavaScript or an ASP script that would create the same page and display the user's entry in the search form as well as the results.
    Rick Trethewey
    Rainbo Design

  3. #3
    Join Date
    Jan 2013
    Posts
    84
    In JS the code is

    PHP Code:
    var elm document.createElement('<div>');
    elm.innerHTML "Hello World!";
    document.body.appendChild(elm); 
    But in ASP i can't find any method... Are you sure that it's possibile and are not confusing with ASP.NET ?

  4. #4
    Join Date
    Mar 2011
    Posts
    1,139
    My point was that you can't do it with just HTML. You need software of some kind. Whether its ASP, PHP, Perl, Ruby, Java, or JavaScript does not matter. It's probably best to do this in JavaScript and AJAX to keep the original page loaded in the user's browser, but it all depends on which tools you know how to use.
    Rick Trethewey
    Rainbo Design

  5. #5
    Join Date
    Jan 2013
    Posts
    84
    Quote Originally Posted by rtrethewey View Post
    My point was that you can't do it with just HTML. You need software of some kind. Whether its ASP, PHP, Perl, Ruby, Java, or JavaScript does not matter. It's probably best to do this in JavaScript and AJAX to keep the original page loaded in the user's browser, but it all depends on which tools you know how to use.
    Many thanks

    I'm trying to do it using javascitp + ajax, but i have only one problem at moment... When i press the "submit" button, it retrieve me Error HTTP 404.0 - Not Found

    This is the html with javascript and ajax
    PHP Code:

    <html>
    <
    head>
    <
    title>Cerca Ragione Sociale</title>
    <
    style type="text/css">
    </
    style>
    </
    head>

    <
    body>

    <
    form method="GET" action="prova()">
     <
    label>Inserisci ragione sociale</label>
       <
    input name="chiave"/>
      <
    label
      
      <
    input type="submit"/>
    </
    form>

    <
    p>Results: <span id="txtHint"></span></p



    <
    SCRIPT LANGUAGE="JavaScript">



    </SCRIPT>



    <script> <!--Ajax-->


    function assegnaXMLHttpRequest() 
    {
        var XHR = null // variabile di ritorno, nulla di default
        var  browserUtente = navigator.userAgent.toUpperCase(); // informazioni sul nome del browser
        
         
         // browser standard con supporto nativo non importa il tipo di browser
         if(typeof(XMLHttpRequest) === "function" || typeof(XMLHttpRequest) === "object")
          XHR = new XMLHttpRequest();
        
         // browser Internet Explorer,  necessario filtrare la versione 4
         else if( window.ActiveXObject && browserUtente.indexOf("MSIE 4") < 0)
         {
            // la versione 6 di IE ha un nome differente per il tipo di oggetto ActiveX
            if(browserUtente.indexOf("MSIE 5") < 0)
             XHR = new ActiveXObject("Msxml2.XMLHTTP");
          
            // le versioni 5 e 5.5 invece sfruttano lo stesso nome
            else
             XHR = new ActiveXObject("Microsoft.XMLHTTP");
         }
        
         return XHR;



    function prova()
    {
        var str="a"
        var xmlhttp=assegnaXMLHttpRequest()
        xmlhttp.open("GET","cerca_ragione_sociale.asp?q="+str,true);
        xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
        xmlhttp.send();
        
        xmlhttp.onreadystatechange=function()
        {
          if (xmlhttp.readyState==4 && xmlhttp.status==200)
            {document.getElementById("txtHint").innerHTML=xmlhttp.responseText;}
         }
    }


    </script>



    </body>
    </html> 
    and this is the server side asp code

    PHP Code:
    <%
    response.buffer true
    Response
    .Expires 0
    Response
    .AddHeader "PRAGMA""NO-CACHE"
    Response.CacheControl "PRIVATE"

    chiave="a"

    dim connstrConn
    strConn 
    "Provider = Microsoft.Jet.OLEDB.4.0; Data Source = " &_
           Server
    .MapPath("md-database\ME.mdb")
    Set conn Server.CreateObject("ADODB.Connection")
    conn.Open StrConn 


    sqlRagioneSociale 
    "SELECT * FROM Anagrafiche Where RagioneSociale like'%" chiave "%'"
    Set rsRagioneSociale Server.CreateObject("ADODB.Recordset")
    rsRagioneSociale.Open sqlRagioneSocialeconn1,3

    Response
    .write("<div id='lista'>")
    do 
    until rsRagioneSociale.EOF true
       Response
    .write(rsRagioneSociale("RagioneSociale"))
       
    Response.write("<br>")    
       
    RsRagioneSociale.MoveNext
    loop   

    Response
    .write("</div>")
    %> 
    Where i wrong?
    Last edited by American horizo; 02-07-2013 at 11:10 AM.

  6. #6
    Join Date
    Nov 2012
    Location
    Jakarta
    Posts
    42
    You can change the form parameter "action" to be the same page as the form is in.

    example:

    form is in page called "myform.asp"

    you change the form action to "action=myform.asp"

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles