# Browser Monitors: how to check if an input form field on the page has a value or if it is empty

**URL:** <https://community.dynatrace.com/t/browser-monitors-how-to-check-if-an-input-form-field-on-the-page-has-a-value-or-if-it-is-empty/39301>\
**Category:** Troubleshooting\
**Tags:** browser-monitors, synthetic-monitoring\
**Created:** [April 17, 2023, 8:44am UTC](https://community.dynatrace.com/t/browser-monitors-how-to-check-if-an-input-form-field-on-the-page-has-a-value-or-if-it-is-empty/39301 "2023-04-17T08:44:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mareeswaran](https://avatars.discourse-cdn.com/v4/letter/m/d2c977/32.png) [@Mareeswaran](https://community.dynatrace.com/u/Mareeswaran)\
**Post date:** [April 17, 2023, 8:44am UTC](https://community.dynatrace.com/t/browser-monitors-how-to-check-if-an-input-form-field-on-the-page-has-a-value-or-if-it-is-empty/39301/1 "2023-04-17T08:44:45Z")

</div>

With help of JavaScript Event, we can extract the value of input field and add the conditional JavaScript&nbsp;code(if else condition) to check if its expected or default or empty value.

 ![image7.jpg](https://global.discourse-cdn.com/dynatrace/original/2X/9/9fc22f707686faa9478ce45ad6d5b61fb36a61f8.jpeg)

For example, consider that current input field is assigned with the default value “Dynatrace” then we can try use the below JS code to check the same,

```javascript
var currentvalue = document.querySelector("#name").value;

var valuetobechecked = "Dynatrace";
if(currentvalue == valuetobechecked)
{
//console.log("current value matches with the expected one");
api.info("current value matches with the expected one");
}
else if(currentvalue.length>0)
{
//console.log("current value not matches with the expected one. Actual Value: " + currentvalue);
api.info("current value not matches with the expected one. Actual Value: " + currentvalue);
//add additional code if its different value.
}
else
{
//console.log("Empty value");
api.info("Empty value");
//add additional code if its empty value.
}

```

---

<div class="post-metadata">

**Author:** ![ChadTurner](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/chadturner/32/161_2.png) [@ChadTurner](https://community.dynatrace.com/u/ChadTurner)\
**Post date:** [May 12, 2023, 6:57pm UTC](https://community.dynatrace.com/t/browser-monitors-how-to-check-if-an-input-form-field-on-the-page-has-a-value-or-if-it-is-empty/39301/2 "2023-05-12T18:57:40Z")

</div>

Very Useful information! thank you!
