# How to send window.location.hash (string after # in the url) along post request

**URL:** <https://www.ruby-forum.com/t/how-to-send-window-location-hash-string-after-in-the-url-along-post-request/141288>\
**Category:** Rails\
**Created:** [June 24, 2008, 11:35am UTC](https://www.ruby-forum.com/t/how-to-send-window-location-hash-string-after-in-the-url-along-post-request/141288 "2008-06-24T11:35:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![g0nzo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/3bc359/32.png) [@g0nzo](https://www.ruby-forum.com/u/g0nzo)\
**Post date:** [June 24, 2008, 11:35am UTC](https://www.ruby-forum.com/t/how-to-send-window-location-hash-string-after-in-the-url-along-post-request/141288/1 "2008-06-24T11:35:00Z")

</div>

Hi,

I got some old javascript tab system and I’m trying to rewrite it to  
make use of window.location.hash to set proper tab after the page is  
loaded. It more or less works, but the main problem is that I got some  
forms and I don’t know how to set their url correctly, so that after  
the form is sent, proper tab is opened again.

I.e. page under “[domain.com/foo/1#tab\_1](http://domain.com/foo/1#tab_1)” has a form that points to  
“[domain.com/foo/1/update](http://domain.com/foo/1/update)”. Is it possible to somehow send  
window.location.hash along the whole request, so that after handling  
the request I can redirect user back to “[domain.com/foo/1#tab\_1](http://domain.com/foo/1#tab_1)”?

I could use remote forms, so that user always stays on the same page,  
but I’d prefer not to use them, unless it can’t be done in any other  
way.

---

<div class="post-metadata">

**Author:** ![g0nzo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/3bc359/32.png) [@g0nzo](https://www.ruby-forum.com/u/g0nzo)\
**Post date:** [June 24, 2008, 12:50pm UTC](https://www.ruby-forum.com/t/how-to-send-window-location-hash-string-after-in-the-url-along-post-request/141288/2 "2008-06-24T12:50:34Z")

</div>

Szymon N. wrote:

> Hi,
> 
> I got some old javascript tab system and I’m trying to rewrite it to  
> make use of window.location.hash to set proper tab after the page is  
> loaded. It more or less works, but the main problem is that I got some  
> forms and I don’t know how to set their url correctly, so that after  
> the form is sent, proper tab is opened again.
> 
> I.e. page under “[domain.com/foo/1#tab\_1](http://domain.com/foo/1#tab_1)” has a form that points to  
> “[domain.com/foo/1/update](http://domain.com/foo/1/update)”. Is it possible to somehow send  
> window.location.hash along the whole request, so that after handling  
> the request I can redirect user back to “[domain.com/foo/1#tab\_1](http://domain.com/foo/1#tab_1)”?
> 
> I could use remote forms, so that user always stays on the same page,  
> but I’d prefer not to use them, unless it can’t be done in any other  
> way.

You should be able to use some javascript to set a hidden form field.  
Maybe onsubmit of the form or onclick of the submit button. The first  
thing I’d try is

form\_tag(blah)  
hidden\_field\_tag :location\_hash  
blah blah  
submit\_tag ‘Save’, :onclick =\> “$(‘location\_hash’).value =  
window.location.hash”  
end

Keep in mind that I haven’t been up very long.

Peace,  
Phillip
