1

I currently have a form with some JavaScript functions and localstorage.

I'm trying to get that when a user types a value into a textbox, the search bar changes the URL from "mysite.com" to "mysite.com/%userinput%". Then that user can send that link to someone else and that person will then see what the original user saw.

1
  • So you want to create some public/private data exchange between two or more users? For example, the first user sends his localstoraged text to your server and then he will receive some generated link, and a pair of a public and private password, so that everyone who opens a page like http://mysite.com/?id=12345&pass=publicpassword can read the latest version of that localstoraged text? Imho it looks like it's possible but not simple to do. Or is it some kind of a chat? ;-) Commented Jul 6, 2013 at 18:53

1 Answer 1

1

This will change the URL after input.

As I understand from your question and comments, you don't want to load the URL, just change it, so try this fiddle: http://jsfiddle.net/GrP6U/2/show/

The code behind is:

JavaScript

var theForm = document.getElementById('theForm');
var theInput = document.getElementById('subj');

theForm.onsubmit = function(e) {
    var myurl = "http://jsfiddle.net/GrP6U/2/show/?input=" + encodeURIComponent(theInput.value);
window.history.pushState('', "Title", myurl);
    return false;
}

HTML

<form id="theForm">
    <input id='subj'/>
    <input type='submit'/>
</form>
Sign up to request clarification or add additional context in comments.

3 Comments

I'd recommend using replaceState() instead of pushState()
@Thumbz, good input. I am just not sure of what OP means/needs/wants. I vote up your comment and he will also read it. Thanks.
Comments may disappear at any moment. It is better to include the information in the answer.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.