Learn how to configure these components to host a python web application
“Pressure is something you feel when you don’t know what the hell you’re doing.” ― Peyton Manning
1. Introduction
Developing a web application is a major task by itself. It has many pieces that need to fit together – front-end HTML, styling in CSS and browser scripting in Javascript. In addition, the back-end also needs to be developed in a suitable server-side framework.
Learn how to use Python Scrapy to Extract information from Websites.
“When life gives you lemons, chunk it right back.”
― Bill Watterson
1. Introduction
Scrapy is a python-based web crawler which can be used to extract information from websites. It is fast, simple and can navigate pages just like a browser can.
A frequent concern when using jQuery for web development is: how to check if a checkbox is checked? There are multiple ways of accomplishing this task which we illustrate with examples in this article.
2. Using the DOM property “checked”
A checkbox is of the type HTMLInputElement and has a property called “checked” whose value is “true” if it is checked.
In the following example, thisrefers to the checkbox DOM element whose property “checked” is being checked. The event handler is invoked after the element is clicked and the function outputs the current state of the checkbox:
If multiple checkboxes match the jQuery selector, this method can be used to check if at least one is checked. Consider this HTML which sets up a bunch of checkboxes with the same class.
<label class="checkbox-inline">
<input id="checkboxRed" type="checkbox"
class="colorCheck"
value="red"> Red
</label>
<label class="checkbox-inline">
<input id="checkboxGreen" type="checkbox"
class="colorCheck"
value="green"> Green
</label>
<label class="checkbox-inline">
<input id="checkboxRed" type="checkbox"
class="colorCheck"
value="blue"> Blue
</label>
The following code prints true if at least one is checked:
In the case when you have multiple related checkboxes, you can get a list of the checked ones by doing:
var boxes = $('.colorCheck:checked');
boxes.each(function(i, chkbox) {
// process each checked box here
});
// How many are checked
console.log('Checked #' + boxes.length);
Conclusion
In this article, we presented various ways of checking the status of a checkbox: whether using jQuery or without. Depending on circumstances, you may prefer one method over another.