Automatic form search using data from a string

Asked

Viewed 267 times

0

I have a string $numero and it returns several numbers.

I also have a home page (index.php) with a form as follows:

<html>
<body>
<div width="100%" height="100%" align="center">

 <!-- htaccess tratando o pagina/ para pagina.php -->

  <form name="formulario" id="formulario" method="post" action="pagina/">


    <input type="text" name="numero" id="numero">
    <input type="hidden" name="inicial" id="inicial" value="S">
    <input type="hidden" name="ws" id="ws">
    <input type="button" value="Consultar" onclick="formulario.ws.value=0; submit()" />
    <input type="button" value="Consultar + webservice" onclick="formulario.ws.value=1; submit()" />
     </form>
    </div>
   </body>
 </html>

The homepage has two buttons. In addition, there is a page (page.php) that handles the search, saved in the database the search among others .

When I enter index.php and fill in the number and click on the second button2 (Query + webservice) it returns what I need on the.php page.

How do I make the automatic searches with a time space X using my string $numero?

That is, I want to optimize the time and not have to search for the index.php form, I mean, I want something automatic (with space of time X) that uses $numero and go do the searches and saving in the database.

  • What is the need to do the automatic searches and still in a certain time, if you put a function equal to setInterval(Function() {scope},tempo) of Jquery will do this, more is not recommended as the application will be using server resource.

  • @HENRIQUELOBO, is that I have a relationship with several numbers I want to research and the webservice accepts requests every 3 seconds. And I want to optimize to not have to do 1 by 1, IE, filling in the field and click search.

1 answer

1


This would be an example to check if the number is filled, if you have, simulate the click on your button that queries the Webservice. The check is in 60 seconds, if you want to change to 4 seconds for example, change the 60000 to 4000.

setInterval( function(){
    var valueNumero = $('#numero').val().trim();

    if(!!valueNumero)
    {
        // Ação no primeiro botão
        // $('button[value="Consultar"]', '#formulario').click();

        // Ação no segundo botão
        $('button[value="Consultar + webservice"]', '#formulario').click();
    }

}, 60000);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.