I have a dashboard with a dropdown. I want to validate that the user has selected a value for this dropdown. If not, I want an alert to display. Where exactly do I paste the javascript code for this?
I tired converting my dashboard to HTML and used this Javascript code. (I haven't included the entire dashboard code in the interest of readability, please let me know if you want me to paste the entire code)
<!DOCTYPE html>
<html lang="en">
<head>
<script>
function validateForm() {
var x = document.getElementById("input1").value;
alert("Your field is "+x);
}
</script>
</head>
<body>
<!--
BEGIN LAYOUT
This section contains the layout for the dashboard. Splunk uses proprietary
styles in <div> tags, similar to Bootstrap's grid system.
-->
<div class="fieldset">
<div class="input input-dropdown" id="input1">
<label>College</label>
<button type="button" onclick="validateForm()">Try it</button>
</div>
</div>
</body>
</html>
But no matter what value I select in the drop-down, the alert displays "Your field is undefined".
To make things clear, I have you two name-value options in my drop-down, USC and UCSD. The initial and default values are set to blank.
Thanks in advance.
... View more