T
T
Tonkonozhenko2014-10-23 18:39:35
JavaScript
Tonkonozhenko, 2014-10-23 18:39:35

How to calculate URL for GET form?

In general, there is a form

<form action="/" method="GET" id="form">
  <input type="text" name="attr" value="value">
</form>

How to get the redirect address using JS?
In my case it will be
/?attr=value
I tried to do like this:
$('#form').submit (e) ->
  # Как получить его вот тут?
  e.preventDefault()

or javascript
$('#form').submit(function(e) {
  // Как получить его вот тут?
  return e.preventDefault();
});

Answer the question

In order to leave comments, you need to log in

4 answer(s)
Y
Yuri Tarakhonich, 2014-10-23
@Tonkonozhenko

Answer here: api.jquery.com/serialize
$( "form" ).serialize();

A
Alexander Sydorenko, 2014-10-23
@San40

If you need exactly the whole URL, then something like this:

$('#form').submit(function(e) {
  var url = $(this)attr.('action') + '/?' + $( '#form' ).serialize();
  return e.preventDefault();
});

R
Rustamka Vorontsov, 2014-10-23
@rmfordev

$('#form').submit(function(e) {
  alert($(this)attr.('action'));
  return e.preventDefault();
});

A
Alexander Taratin, 2014-10-23
@Taraflex

Actually why do you need it?
Maybe you want to send the form via ajax?
If so, then there is malsup.com/jquery/form

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question