0

First of all, I can't use the action='' attribute. That's why I use on submit.

Here my code:

<form class="search" role="search" method="get" onsubmit="window.location.href='home.php?m=search&q='; return false;">
  <input type="text" placeholder="Rechercher..." name="s">
</form>

How can I get my input content after my onsubmit url ?

Can jQuery could get this content and put it in this address ? How do do this ?

Thanks.

  • 2
    missing action attribute – Ejaz May 04 '14 at 13:31
  • c'mon @Ejay first thing he says "First of all, I can't use the action='' attribute. That's why I use on submit." – 13ruce1337 May 04 '14 at 13:32
  • You miss the first line. – user3504260 May 04 '14 at 13:32
  • @13ruce1337 c'mon man whay can't he use that? If so how is he using alternative? – Vinay May 04 '14 at 13:33
  • @JJPA ask him not me. I'm just staring at the problem thinking the only solution is to use an AJAX call. I think with the way he has it now the form doesn't get submitted to where he wants, he is just redirecting there. – 13ruce1337 May 04 '14 at 13:35
  • For the record, if the form doesn't have an action, it uses the documents address effectively submitting the data to the page itself. [Is it a good practice to use an empty URL for a HTML form's action attribute? (action=“”)](http://stackoverflow.com/questions/1131781/is-it-a-good-practice-to-use-an-empty-url-for-a-html-forms-action-attribute-a) – 13ruce1337 May 04 '14 at 13:40
  • @13ruce1337 bI'm asking u bcoz there are rules You can point him to those you know it. its always about rules don't you think so – Vinay May 04 '14 at 13:44

1 Answers1

4

I believe you want

window.location.href='home.php?m=search&q='+this.s.value; return false

Possibly even

window.location.href='home.php?m=search&q='+encodeURIComponent(this.s.value); return false

to be sure

To use the form action, you could do

onsubmit="this.action='home.php?m=search'"

and change name="s" to name="q"

mplungjan
  • 169,008
  • 28
  • 173
  • 236