How to check whether checkbox element is checked or not by ID/name in Javascript?

You can check whether a given checkbox field is checked or not with Javascript by querySelector or getElementById method.

There are lots of ways to fetch Checked element results by native javascript.

Let’s give a code snippet for the Checkbox Element,

<div class="field choice">
    <input type="checkbox" name="show-password" title="Show Password" id="show-password" class="checkbox">
    <label for="show-password" class="label">Show Password</label>
</div>
  • Checkbox Element checked with querySelector method,
    let showPasswordField = document.querySelector("input[name=show-password]"); // BY Name Attribute
    let showPasswordField = document.querySelector("#show-password"); //By ID
    if (showPasswordField) {
     let result = showPasswordField.checked;
     console.log(result);
    }
  • To Get Results by id attribute,
let showPasswordField = document.getElementById("show-password");
if (showPasswordField) {
    let isChecked = showPasswordField.checked;
    console.log(isChecked);
}
  • To Get Results by name attribute,
    Here Checkbox field name attribute value is “show-password”,
let showPasswordField = document.getElementsByName("show-password");
if (showPasswordField.length !== 0) {
    let isChecked = showPasswordField[0].checked;
    console.log(isChecked);
}
  • Using jQuery
$("#show-password").is(':checked')

How to set stores URL configuration by env.php file in magento 2?

Magento env.php file stores  Environment specific configuration and system-related sensitive data.

With the help of the ‘system’ array node, A System node locks the provided configuration values in the env.php file and disables that field in the admin panel.

Sensitive values might be API keys for the connector, Payment related Stuff, Email Addresses, URLs, and Private Contact related information.

We will set the URL value with the env.php file.

You can’t able to modify it from the Stores -> Configuration -> General -> Web -> Base URL field. Continue reading “How to set stores URL configuration by env.php file in magento 2?”

Magento 2 Update Product Stock Inventory by Rest API.

You can Update Product Stock related information by REST API with the use of endpoint URL /V1/products/:productSku/stockItems/:itemId.

You can manage Stock Inventory related data with REST API with the given payload as below.

Action: PUT

Header: Authorization: Bearer <ADMIN_TOKEN> Continue reading “Magento 2 Update Product Stock Inventory by Rest API.”