Mike K Mike K - 1 year ago 103
HTML Question

Append URL from user input and go

I'm trying to get a input box that a patron could type in a word and it would take that input and append a URL in the middle.

link example would be https://proxyaddress/login=?url=http://libraryaddress/database/SearchResults.jsp?result_start=0&result_items=48&result_layout=GRID&query1_modifier=AND&query1=USERSEARCHTERM&query1_field=CONTENT

where the part changed by input would be USERSEARCHTERM

I've found solutions online but they all just load the proxy address and stop there.

Any help would be greatly appreciated, thanks!

Answer Source

The proxy address will need to be corrected to a valid DNS (.com,IP) But this captures the user input, concats the input with the URL format and changes the window location.

You'll also want to prevent XSS on any user input on the backend.

<form id="my-form">
<input type="text" id="search">
<button type="submit">Search</button>

var form = document.getElementById('my-form');
var input = document.getElementById('search');

function processForm(e) {
    if (e.preventDefault) e.preventDefault();
    var inputVal = input.value;
    var combinedUrl = "https://proxyaddress/login=?url=http://libraryaddress/database/SearchResults.jsp?result_start=0&result_items=48&result_layout=GRID&query1_modifier=AND&query1=" + inputVal + "&query1_field=CONTENT";

    window.location.href = combinedUrl;

    return false;

if (form.attachEvent) {
    form.attachEvent("submit", processForm);
} else {
    form.addEventListener("submit", processForm);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download