I have an event handler listening on a jQuery-"submit" event.
The form looks like this:
<form class="registration well">
<fieldset>
<legend>registration</legend>
<div class="control-group">
<label class="control-label" for="_user_username">username</label>
<div class="controls">
<input type="text" id="_user_username" name="username" placeholder="george78" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="_user_email">email:</label>
<div class="controls">
<input type="email" id="_user_email" name="email" placeholder="george@example.com" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="_user_password">password:</label>
<div class="controls">
<input type="text" id="_user_password" name="password" placeholder="my password" />
</div>
</div>
<button type="submit" class="btn btn-primary">register</button>
</fieldset>
</form>
The event handling part like this:
e.preventDefault();
console.log(e);
var user = {
username: $(e.target[1]).val()
, email: $(e.target[2]).val()
, password: $(e.target[3]).val()
};
This works so far. I now would just have something like a common valid way to foreach this process. The hard thing about it is that the first element in the events target array is the fieldset and the last on is the button. So I somehow have to get the elements between.
Somebody an idea how I could do this?
Why don’t you just get them by id: