How do I make so that the load buttons java functions works from a box with just one button, instead of two separate buttons that call on two "different" JavaScript functions?
In other words clarify the question: I have two different functions that I need to fire, but from a with one to fire the function I choose in the selection box.
Remember: That the warnings and confirmation should still work, so there for I can not us one and the same load function for both options, because of the different warnings and confirmation.
NOTE: If it is possible without using jquery only with JavaScript that would be great, but if there is a solution with jquery then that will is good too as long as it works.
Here are my JavaScript codes:
function loadFileAsTextUNLIMITED()
{
valid = true;
if(document.fileTextBox.fileLoadName.value == "")
{
alert ("Please attach a file to upload")
valid = false;
}
{
if (confirm("Are you sure you want upload unknown file? Remember that if you uploaded a file that is not a text or a web page source code file, it may hang up your computer or it may destroy the file when you try to save it. So if you chose to upload it this way, you are doing it on your own risk.") )
{
var fileToLoad = document.getElementById("fileToLoad").files[0];
var fileReader = new FileReader();
fileReader.onload = function(fileLoadedEvent)
{
var textFromFileLoaded = fileLoadedEvent.target.result;
document.getElementById("inputTextToSave").value = textFromFileLoaded;
};
fileReader.readAsText(fileToLoad, "UTF-8");
} else {
window.alert("Good, it is advised you use the normal Load Text button and this button only if you have too. ")
}
}
}
function loadFileAsText()
{
valid = true;
if(document.fileTextBox.fileLoadName.value == "")
{
alert ("Please attach a file to upload")
valid = false;
}
{
var fup = document.getElementById('fileToLoad');
var fileName = fup.value;
var ext = fileName.substring(fileName.lastIndexOf('.') + 1);
if(ext == "TXT" || ext == "txt" || ext == "HTML" || ext == "html" || ext == "HTM" || ext == "htm" || ext == "JS" || ext == "js" || ext == "CSS" || ext == "css" || ext == "PHP" || ext == "php" || ext == "DOWNLOAD" || ext == "download")
{
var fileToLoad = document.getElementById("fileToLoad").files[0];
var fileReader = new FileReader();
fileReader.onload = function(fileLoadedEvent)
{
var textFromFileLoaded = fileLoadedEvent.target.result;
document.getElementById("inputTextToSave").value = textFromFileLoaded;
};
fileReader.readAsText(fileToLoad, "UTF-8");
}
else
{
alert("Upload a text or a web page file with source codes");
fup.focus();
return false;
}
}
}
Here are those parts of my HTML codes for it:
<input type="file" id="fileToLoad" name="fileLoadName">
<input type="button" onclick="loadFileAsText();showFileSize();" value=" Load Text / Source Code Files ">
<br>
<input type="button" onclick="loadFileAsTextUNLIMITED();showFileSize();" value=" On your own risk Load Any File Type">
<br>
<textarea id="inputTextToSave" name="inputTextToSave" rows="10" cols="70" placeholder="Type your text here:"></textarea>