How can I insert a variable into the resulting url parameter string after submitting my GET form?

Landon

I have a form that queries a library database on another site. It works perfectly if I only include input fields for the "format" and "keyword" because the resulting parameters passed to the url come out in the correct order and the destination site recognizes it.

However, I also need my form to have an input field to select to search by "Author", "Title", "Subject" etc. This is what causes the problem. The destination site only recognizes this parameter if it is in the middle of the url (inside the keyword parameter).

My current resulting url: http://alpha2.suffolk.lib.ny.us/search~S50/X?SEARCH=harry&searchscope=50&SORT=D&m=b

What I need the url to look like: http://alpha2.suffolk.lib.ny.us/search~S50/X?SEARCH=t:(harry)&searchscope=50&SORT=D&m=b

If you compare the two you will notice a couple differences. First, ignore the parentheses around harry. That doesn't make a difference. The real issue is how do I get the "t:" to be inserted into my url? The "t:" comes from selecting "Title" as the thing to search by.

Here is my current form HTML (If you remove the "searchtype" select box at the bottom the form will execute without errors, but I need it to execute with it.)

<form class="form-inline" role="search" method="get" name="searchform" id="searchform" action="http://alpha2.suffolk.lib.ny.us/search~S50/X">
                  <div class="form-group" style="float: left; margin-top: 6px;">
                    <label class="form-title">Search Collection</label>
                  </div>
                  <div class="form-group">
                    <input type="text" value="" name="SEARCH" id="SEARCH" placeholder="Enter Search Terms..." />
                    <input type="hidden" value="50" name="searchscope" />
                    <input type="hidden" value="D" name="SORT" />
                  </div>
                  <div class="form-group" style="float: left; margin-top: 3px;">
                    <label for="searchformat">For:</label>
                    <select name="m" id="m">
                            <option value="">ANY</option>
                            <option value="a">BOOK</option>
                            <option value="e">EBOOK DOWNLOAD</option>
                            <option value="l">LARGE PRINT BOOK</option>
                            <option value="b">BLU-RAY</option>
                            <option value="g">DVD</option>
                            <option value="i">AUDIO BOOK CD</option>
                            <option value="h">AUDIO BOOK MP3CD</option>
                            <option value="x">EAUDIOBOOK DOWNLOAD</option>
                            <option value="q">PLAYAWAY</option>
                            <option value="j">MUSIC CD</option>
                            <option value="p">MAGAZINE/NEWSPAPER</option>
                            <option value="n">EMAGAZINE DOWNLOADS</option>
                            <option value="v">PLAYAWAY VIEW</option>
                            <option value="s">VIDEO GAME</option>
                            <option value="r">CD-ROM</option>
                            <option value="d">VHS</option>
                            <option value="t">GAMES/PUZZLES</option>
                            <option value="f">DIGITAL IMAGE</option>
                            <option value="z">EVIDEO DOWNLOADS</option>
                            <option value="y">EMUSIC DOWNLOADS</option>
                            <option value="c">SHEET MUSIC</option>
                            <option value="m">MAP</option>
                            <option value="w">ONLINE RESOURCE</option>
                            <option value="o">OTHER MATERIALS</option>
                    </select>
                  </div>
                  <div class="form-group" style="float: left; margin-top: 3px;">
                    <label for="searchtype">By:</label>
                    <select name="" id="searchtype">
                            <option value="a:"> Author</option>
                            <option value="t:"> Title</option>
                            <option value="d:"> Subject</option>
                            <option value="N:"> Note</option>
                            <option value="" selected="selected"> Keyword</option>
                    </select>
                  </div>
                  <button class="btn btn-primary" id="searchsubmit" type="Submit">GO</button>
                </form>

EDIT:

The attempted Javascript (as requested in the comments):

<script>
function searchSubmit() {
    m = document.getElementById("m").value;
    t = document.getElementById("searchtype").value;
    a = document.getElementById("searcharg").value;
    var newurl = "alpha2.suffolk.lib.ny.us/search/X~S22?SEARCH="; + t + a + "&searchscope=50&SORT=D&m=" + m;
    var searchform = document.getElementById("searchform");
    searchform.action = newurl; searchform.submit();
} 
</script>
Salmin Skenderovic

What I would do is get the searchtype-value and add it to the input-search before submitting. Here is a JS-fiddle example:

$(document).ready(function(){
    $("#searchform").on("submit", function(e){
        var keyWord = $("#SEARCH").val();
        var searchtype = $("#searchtype").val();
        $("#SEARCH").val(searchtype + keyWord);
    });
});

Collected from the Internet

Please contact javaer1[email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I get a URL parameter with jQuery?

How to avoid URL $_GET variables after submitting a form with ajax?

How can I get resharper to know that my variable is not null after I have called an extension method on it?

How can i get the parameter form label when parameter is variable in batch file?

How can I redirect to a new page after submitting a form using Jinja template?

How can I get a variable image URL?

How can I get the errors of my form into a string in Symfony 4?

How can I edit a google sheets HTML UI element after submitting form?

How can I empty this AngularJS form after submitting the data?

How can I get the form values to appear in the table after submitting?

How do I get errors which are handled serverside in a ajax error message after submitting a form?

How to get a popup box after submitting a form?

can I get text from html and put it into variable in php without submitting a form?

How can I delete GET url parameter after creating array in django?

Can't retrieve variable from url with Flask app after submitting search form

How can I get the URL parameter after the domain name in php/apache configuration?

In my spring login form url getting changed after submitting the form

How can I convert my variable into a string?

How can I show the output vertically after submitting the html form?

How can I edit the resulting String?

How can I create a browser shortcut to append a parameter to current URL and then load the resulting url?

I can't get my form to submit after using preventdefault

How can i get url parameter in laravel?

How can i get data or pass a data from one page to another after submitting a form in reactjs

How can i get my url parameter right on Javascript?

How can i redirect on submitting my form in reactjs and using formik

How can I get my parameter object AFTER my method has modified the parameter?

How can I decrement a field value from firestore after submitting a form successfully?

How to remove 'GET?' string from URL when submitting a GET form