I am trying to create a small web application (using HTML and javascript on client side and may be servelets for server side) to execute some automation scripts. The HTML file has a form which has some input fields and submit button. I want to disable the button once the form is submitted and enable it only when new data is entered in the fields. How do I achieve it in the javascript?
I am trying to view it on Chrome browser and the enabling and disabling of the button works fine when the button is outside form tag but that does not get the form data.
Also, i tried changing button type to "button" instead of "submit" but the javascript did not execute at all. The only time when the method startAutomation() executes is when the button is outside form tag. However, javascript method call works fine for other input elements inside form.
I suspect that browser is refreshing too fast and hence not visible. How do I resolve this problem?
Below is my HTML code:
<!DOCTYPE html>
<html>
<head>
<title>Test Automation</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script type="text/javascript">
function startAutomation() {
document.getElementById("startAutomation").disabled = true;
document.getElementById("status").innerHTML = "Automation execution started...";
}
</script>
<noscript>Sorry, your browser does not support JavaScript!</noscript>
</head>
<body>
<form name="setConfig">
<fieldset>
<label class="required-field">Enter your email id to get notified : </label>
<input type="text" name="emailId" size="60"> </input>
<br>
<button type="submit" value="Start Automation" id="startAutomation" style="font-size:105%;" onclick="startAutomation();">Start Automation</button>
<br>
</fieldset>
<fieldset>
<p style="font-size:120%;" id="status">Execution status</p>
</fieldset>
</form>
</body>
</html>
What i want to achieve:
- Enter the data into the form.
- Click start automation button to submit the form (data available in the URL)
- Immediately disable the button and replace "execution status" message with "automation execution started" message.
- When the user clicks on any of the fields in the form to re enter new information, enable the button and change the message back to execution status.
Please let me know if there is any other way to achieve this. I am new to web development.
startAutomation();
, then submit the form. With the form having noonsubmit="return false;"
and noaction
, that essentially causes a page reload. - Chris G