// Form Events with jQuery
// Part 1
// Submission
//
// When a new issue is submitted
// a. Add a new "issue" element to the #issues div
// You can add this as a list/list-item
// Or as a table row (you'll need to set up the table)
// b. Empty out the form after submission
$("#myForm").on('submit', function() {
console.log($(this).serializeArray());
var newIssue = $('input:text').val();
var priority = $('select option:selected').text();
var isBoss = $('input:checkbox').prop('checked');
$('#issueList').append('<li>'+ formatIssue(priority,newIssue,isBoss) + '</li>');
$('#issues').show();
$('input:text').val('');
$('select').val('0');
return false;
});
function formatIssue(priority,description,isBoss){
priority = priority || 'Low';
var issue = " [" + priority + "] ";
if(isBoss){
issue += "(boss)";
}
return issue + description;
}
// Part 2
// Validation
//
// Using jQuery/JavaScript
// Add some basic validation rules to the form
// a. Description field is required
// b. When the user submits the form validation should be checked
// c. When invalid, display a message to the user somewhere in the page, ex: "Description is required, try again!"
// d. Bonus: Add a style to fields so that they have a red border when invalid
// Part 3
// Being nice to users
//
// If a user types in the word "urgent" to the description
// Then the form should auto-select a priority of "medium"
// And the background of the form should be set to a "lightred"
// Part 4
// Being nice to the boss
//
// If a user checks "are you my boss?"
// Then the form should auto-select a priority of "high"
// and set the class of the form container to "boss-level"
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.