0

I'm a designer trying to update some forms on our website. I'd like to use jquery to add the search term to the URL we are using as the action in our search forms. Our current website is legacy asp.

A new approach is necessary because our current forms search a database on another website (contentdm, hosted by OCLC), and in an upgraded version our current forms will not work.

The new method is to write items into the URL (see searchterm/ohio in the URL below):

http://sandbox.contentdm.org/cdm/search/collection/p10010coll1/searchterm/ohio

I know how to add the latest jquery library to my page, but I'm not very familiar with how to write the script to get it to work.

The previous form uses this method:

<form method="get" action="http://content.wisconsinhistory.org/cdm4/results.php">
<input type="hidden" name="CISOOP1" value="all" />
<input type="hidden" name="CISOFIELD1" value="CISOSEARCHALL" />
<input type="hidden" name="CISORESTMP" value="results.php" />
<input type="hidden" name="CISOVIEWTMP" value="item_viewer.php" />
<input type="hidden" name="CISOMODE" value="grid" />
<input type="hidden" name="CISOGRID" value="thumbnail,A,1;" />
<input type="hidden" name="CISOBIB" value="title,A,1,N;" />
<input type="hidden" name="CISOTHUMB" value="20 (4x5);title" />
<input type="hidden" name="CISOTITLE" value="20;title,none,none,none,none" />
<input type="hidden" name="CISOHIERA" value="20;titlea,title,none,none,none" />
<input type="submit" value="Search" class="button" />
</form>

I've been searching google to see how I can get the form to go to a results page more like the new URL: http://sandbox.contentdm.org/cdm/search/collection/p10010coll1/searchterm/ohio

And, I have a start below. But I know I messed up. I think first I have to get the value that the user entered, and then I have to add it into the URL... I just don't know how to write it.

<script>                                    
$(document).ready(function(){
    $('.searchform').append('action="http://sandbox.contentdm.org/cdm/search/collection/p10010coll1/searchterm/' + 'input[name=searchvalue]');
}); 
</script>

<form method="get" class="searchform" action="http://sandbox.contentdm.org/cdm/search/collection/p10010coll1/searchterm/">
<input type="text" name="searchvalue" tabindex="1">
<input type="submit" value="Search" class="button" />
</form> 

I just know there has to be a way to do this! I am thankful for any help you can provide. Thanks!

1 Answer 1

0
$('#.searchform').submit(function(e) {
    e.preventDefault();
    var action = $(this).attr('action') + '/' + $('input[name=searchvalue]', this).val();
    window.location.href = action;
});

I have edited the code to prevent the submit and just go to the URL with the search term appended. Will that work?

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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