HTML Submit Button with two JavaScript functions but have a setTimeout between them

3 days ago 4
ARTICLE AD BOX

I have two JavaScript functions and i have a submit button for each function, whats the best implementation to add a few seconds wait between the two functions for example in JavaScript.

setTimeout(function(){ //do what you need here }, 5000);

I have searched for other examples but those did not fit this purpose.

I have two scripts.

The one below writes text inputed to a text file.

function SaveData() { var oFSO = new ActiveXObject("Scripting.FileSystemObject"); var folder = "C:\\Temp"; var filePath = folder + "\\Test.txt"; if (!oFSO.FolderExists(folder)) { oFSO.CreateFolder(folder); } var oFile = oFSO.CreateTextFile(filePath, true); var output = "STORE_NAME=" + STORE_NAME.value + "\r\n" + "STORE_NUMBER=" + STORE_NUMBER.value + "\r\n" + "EPM_NUMBER=" + EPM_NUMBER.value + "\r\n" + "MCID=" + MCID.value + "\r\n" + "SCREEN_SN=" + SCREEN_SN.value + "\r\n" + "customer_name=" + customer_name.value + "\r\n" + "scanner_type=" + scanner_type.value + "\r\n"; oFile.Write(output); oFile.Close(); //alert("Saved to " + filePath); } </script>

And the other opens a batch file with the data from the text file generated by the above.

<script type="text/javascript" language="javascript"> function RunFile() { WshShell = new ActiveXObject("WScript.Shell"); WshShell.Run("test.bat", 1, false); } </script>

I did try adding the setTimeout function to the script above but it ignored it.

I have two buttons below.

<input class="submit_button" type="button" accesskey="s" value="Submit Data" onClick="SaveData()"/> <input class="submit_button" type="button" value="Run Notepad" onclick="RunFile();"/>

I have tried the below and it does work but would prefer to have a few seconds between them.

<input class="submit_button" type="button" accesskey="s" value="Submit Data" onClick="SaveData(); RunFile();" />
Read Entire Article