Question

let me start by saying it may look simple but im finding it extremely difficult.

ive made a search script that uses PHP and to fetch a result would look like this

search.php?term=alice&submit=Submit

Standard stuff.. problem is, i use an SPI with AJAX and PHP so my results would have to load dynamically into a div, whilst still keeping the hash value, as not to lose the page the user had visited previous to searching.

jQuery.history.js is the plugin i use for back button support, which requires links to be like such:

<a href="#home">Home Page</a>

this would load 'home.html' into a div named pageContent. as far as i know theres no way to call php files unless you develop a little hack, which i have,

here is my JavaScript/jQuery for my search form:

<script language="JavaScript">
$(document).ready(function() { 
    // bind form using ajaxForm 
    $('#search1').ajaxForm({ 
        // target identifies the element(s) to update with the server response 
        target: '#pageContent', 

        // success identifies the function to invoke when the server response 

        success: function() { 
            $('#pageContent'); 
            var hash = '#search.php?term='+($('#query').val()+'&submit=Submit').replace(/ /g, '+');
            var stripped = hash.replace(/(<([^>]+)>)/ig,""); 
            update(window.location.hash = stripped);

        } 

    }); 
});

</script>

Heres the form:

<form id="search1" action="search.php" method="post">
    <input id="query" type="text" name="term" />
    <input type="submit" name="submit" value="Submit" />
    </form>

My problem is this: ive tried this.form.reset(); this: Resetting a multi-stage form with jQuery , yet none of this works. please help me if you know a way of doing this..

Was it helpful?

Solution

$('#query').val(DefaultValue);

with this u can set your value to whatever you want, like blank: '';

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top