Reputation: 14161
I have a little form and I intend to allow the user to jump to a section by entering a number and this becoming an anchor link:
Jump to <input type="text" value="" name="a_gobox" id="a_gobox" />
<input type="image" class="button" name="submit" src="/images/gobutton.png" alt="Go" />
So if the user enters "7" then I want the hash anchor of the page to change to #section7
.
It is important that the actual hash value changes in the address bar as well as reflecting this on the page.
How can I achieve this?
Upvotes: 0
Views: 82
Reputation: 1847
You could use something like
$('.button').on('click', function() {
var which_number = $('#a_gobox').val(),
section_to_jump_to = '#section_' + which_number;
window.location.hash= section_to_jump_to;
});
And a little fiddle http://jsfiddle.net/ftWZh/1/
Upvotes: 0
Reputation: 66693
You should be able to simply do:
window.location.hash = '#' + $('#a_gobox').val();
Upvotes: 2