front-end-developer_1_
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Front-End-Developer - Level 1<br />
$(document).ready(function() {<br />
$("#blanks form").submit(function(event) {<br />
$(".person1").app<strong>end</strong>("blah blah");<br />
$(".person2").app<strong>end</strong>("blah blah");<br />
$(".animal").app<strong>end</strong>("blah blah");<br />
$(".exclamation").app<strong>end</strong>("blah blah");<br />
$(".verb").app<strong>end</strong>("blah blah");<br />
$(".noun").app<strong>end</strong>("blah blah");<br />
$("#story").show();<br />
});<br />
});<br />
event.preventDefault();<br />
Notice that we've added a parameter event to the callback function we passed to<br />
submit() method. When the form is submitted, jQuery runs the callback function and<br />
passes in something as an argument. We don't know what this "something" is - we just know<br />
that it somehow represents the event of the form being submitted, and so we give the<br />
parameter the name event . And we know that if we call the method preventDefault() on<br />
this event thing, it will stop the form from submitting.<br />
This is a pretty confusing concept. If you aren't at least 70% clear on the previous<br />
paragraph, stop and re-read it, slowly and carefully. If you are at least 70% clear, come back<br />
and re-read it a couple more times after you finish this lesson. You might also re-visit the<br />
lesson on Writing functions, which includes an explanation of arguments and parameters.<br />
Now, we need to actually get the values from the form. If we open up the JavaScript console<br />
on the page and run:<br />
$("input#person1").val();<br />
We can see that this jQuery method returns the value from the input as a string. Since the<br />
app<strong>end</strong>() method takes a string as an argument, we can update our code like this:<br />
scripts.js<br />
Forms<br />
180