Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Appending a hash '#' symbol to url with a form action?

So I've got a form with a submit button and a text input...

I want: http://localhost/

to become: http://localhost/#q=

I did a solution in javascript which involves changing the "action" of the form to the url with the hash onclick.. but this doesn't work in IE.

Anyone have a solution that works on all browsers?

like image 646
rawrrrrrrrr Avatar asked Jul 30 '09 00:07

rawrrrrrrrr


People also ask

How do you add to a hash?

Adding and Removing Keys and Values And, you can add keys and values to a hash table by using the addition operator ( + ) to add a hash table to an existing hash table. For example, the following statement adds a "Time" key with a value of "Now" to the hash table in the $hash variable.

How do you add a hash to an array?

To append a new value to the array of values associated with a particular key, use push : push @{ $hash{"a key"} }, $value; The classic application of these data structures is inverting a hash that has many keys with the same associated value. When inverted, you end up with a hash that has many values for the same key.

What is a ruby hash?

In Ruby, Hash is a collection of unique keys and their values. Hash is like an Array, except the indexing is done with the help of arbitrary keys of any object type. In Hash, the order of returning keys and their value by various iterators is arbitrary and will generally not be in the insertion order.

Can a hash key have multiple values?

Each key can only have one value. But the same value can occur more than once inside a Hash, while each key can occur only once.


2 Answers

I ran into a similar problem with IE not pulling in the hash from the form action.

I had a form

<form action="/#search" id="search-form">
   <input type="text" class="search-query" placeholder="Search" name="q">
</form>

When I submitted this form in anything but IE the page went to

/?q=searchparams#search

But in IE it went to

/?q=searchparams

To solve this I used JQuery to bind to the submit action and redirect to the page I wanted it to go to.

$("#search-form").submit(function() {
    var query = $('input[name="q"]').val();
    window.location.href = 'index.php?q='+query+'#search';
    return false;
}); 

It's been working fine since.

like image 79
Jbrown Avatar answered Sep 28 '22 07:09

Jbrown


<script>
function add_hash() {
    window.location.hash = "q=";
}    
</script>

<form onsubmit="add_hash(); return false;">

Not sure what you're doing with this, though.

like image 40
Luca Matteis Avatar answered Sep 28 '22 07:09

Luca Matteis