$("form").submit(function () {
var english = $("input #rawr").val()
$("h1 em").append(" " + english + " "); //Current submit brings up 'undefined'
return false;
});
<form>
<input type="text" name="rawr" id="rawr" />
<input type="submit" />
</form>
views:
122answers:
3Awesome. This worked, but why does the input selector mess up the function?
jensechu
2009-09-22 15:34:20
+2
A:
You are using the ancestor descendant selector, which isn't what you want.
The selector is looking for an element with an id = rawr
, child of an INPUT element .
Remove the space on your selector:
var english = $("input#rawr").val();
or don't use the tag name at all, since you have a unique ID:
var english = $("#rawr").val();
Also don't forget your semicolons!
CMS
2009-09-22 15:34:13
A:
$("form").submit(function (e) {
e.stopPropagation();
var english = $("#rawr", $(this)).val();
$("h1 em").append(" " + english + " ");
});
<form>
<input type="text" name="rawr" id="rawr" />
<input type="submit" />
</form>
andres descalzo
2009-09-22 15:40:23