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

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" has a form that points to
"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"?

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.

Szymon Nowak 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" has a form that points to
"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"?

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