Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am trying to display search query results on a separate page. I copied the code from a forum, but since the display page isn't php, I'm not sure it will work.

Here is the code from the home page:

<form action="search" method="post">
<input type="text" name="q" />
<input type="submit" name="search" value="Search" />
</form>

I want the search results to show on mysite.com/search (obviously)

The code on mysite.com/search is as follows:

<div id="cse" style="width: 100%;">Loading</div>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">//
  google.load('jquery', '1');
  google.load('search', '1');
  google.setOnLoadCallback(function(){
    var customSearchControl = new google.search.CustomSearchControl('XXXXX');
    customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
    customSearchControl.draw('cse');
    $(".gsc-input").val("<?php echo $_POST['q']; ?>");//insert into search field requested search text
    $(".gsc-search-button").click();//call button click event, show results
  }, true);
// ]]></script>

Do I have any options? Is there a workaround?

share|improve this question

2 Answers 2

since the display page isn't php

Then you can't use $(".gsc-input").val("<?php echo $_POST['q']; ?>");, but could use something like

$.get('path-to-php-script/query.php', function(data) {
   $(".gsc-input").html(data);
   alert('Load was performed.');
});

The idea is that you just use jQuery to retrieve and manipulate the data that you need to run through PHP script(s) before they're returned to the HTML-only display page.

share|improve this answer

You can achive like this Put this code in your head tag

    <script language="javascript"> 
    function changeData(fromDiv)
    {
        document.getElementById('toDiv').innerHTML = fromDiv.innerHTML;
    }
    </script>

And This in your body tag

    <div id="toDiv"></div>
    <div id="fromDiv" onclick="changeData(this)">Hello World I am here</div>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.