开发者

How to use the textbox value to fetch the records and to display it in the same page

i am having a Form like

  <script language="javascript" type="text/javascript">

     function formfn()
  {
   var str = document.getElementById('TitleSearch').value;
  alert(str);//displays the keyword like database
   }

   </script>






  <form name="f1" method="post">
   <p><label for="TitleSearch">Keywords:</label> 
   <input title="Keyword" size="40" valu开发者_如何学运维e="" id="TitleSearch"></p> 
   <p>
   <input type="submit" id="im-search" value="Search" name="im-search" onClick="formfn();"></p>
      </form>

I am having a page where in the top i have this form on search it has to take the value of the textbox TitleSearch and to use this to retrieve the records matching by

      <?php
$db         =& JFactory::getDBO();
    $query =  'SELECT * from #__chronoforms_Publications where keyword like "%valueretrieved%" ';
    $db->setQuery($query);
    $rows = $db->loadObjectList();
      //echo $rows;
      ?>

Once the search button is clicked the text box value of the keyword is retrieved . I am trying to use this value in the select query to fetch the records and to display in the same page..

How to do so..


Pls change the button type

Here is the modified code:

<script language="javascript" type="text/javascript">
 function formfn()
 {
   var str = document.getElementById('TitleSearch').value;
   alert(str);
 }
</script>

<form name="f1" method="post">
   <p><label for="TitleSearch">Keywords:</label> 
     <input title="Keyword" size="40" value="" id="TitleSearch" 
      name="TitleSearch"></p> 
      <p> <input type="button" id="im-search" value="Search" name="im-search" 
       onClick="formfn();"></p>
</form>


You need to look into AJAX

Here is the simple version from w3schools http://www.w3schools.com/PHP/php_ajax_database.asp

alternative is jQuery: The first of the links here can get you to the next step - google for php ajax jQuery


This is AJAX database. See http://www.w3schools.com/php/php_ajax_database.asp which gives a really specific details. You need a separate PHP page to call your DB.

I did this function before. Just make sure your PHP page is not accessible and safe enough.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜