Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Jul 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question File Name and Extension To An Alert

    I can't seem to figure why it will not return the file's name and extension.

    It is suppose to return the XML file's name and extension in an alert message.

    It appears that this part of the code is not working. I deduced this by just declaring an alert at the beginning of the called function (msg()), and with the onClick function of the button. The onClick function works, but the msg() is not being called or it doesn't know what to do.

    "document.forms["myForm"]["libxml"].value"

    Code:
    <html>
    <head>
    <script type="text/javascript">
    function msg(var URL)
    {
    	if (URL==null || URL=="" || !fileTypeParser(URL))
    		return('Please enter a XML file');
    	if (fileTypeParser(URL))
    		return(URL);
    	else
    		return('You have the wrong data type');
    }
    
    function fileTypeParser(var URL)
    {
    	var array = URL.split(".");
    	if(array[1]=="xml")
    		return true;
    	else
    		return false;
    }
    </script>
    </head>
    <body>
    
    <!-- This code is to simply out put the file's name and extension as an alert -->
    
    <form name="myForm">
    <input type="file" name="libxml" accept="text/xml" />
    <input type="button" value="Submit" onclick="alert(msg(document.forms["myForm"]["libxml"].value))"/>
    </form>
    </body>
    </html>
    Any help would be greatly appreciated.

    Thanks.

  • #2
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    Remove var from the function arguments ( msg(URL) ).

    And check the error console to see if any error messages exist.
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #3
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,911
    Thanks
    15
    Thanked 227 Times in 227 Posts
    I may come back and 'speriment with this one a bit, it's an interesting puzzle to say the least. The form submits onmouseup so any script action before submission requires onmousedown. When the form submits a new page loads, you see? And I didn't know file type inputs returned a value! And I find that first if statement to be most puzzling.

  • #4
    New to the CF scene
    Join Date
    Jul 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    Quote Originally Posted by WolfShade View Post
    Remove var from the function arguments ( msg(URL) ).

    And check the error console to see if any error messages exist.
    So you mean like this:

    Code:
    <script type="text/javascript">
    function msg(URL)
    {
    if (URL==null || URL=="")
    	return('Please enter a database');
    if (fileTypeParser(URL))
    	return(URL);
    else
    	return('You have the wrong data type');
    }
    
    function fileTypeParser(URL)
    {
    	var array = URL.split(".");
    	if(array[1]=="xml")
    		return true;
    	else
    		return false;
    }
    </script>
    I still can't enter the msg() function, just checked it.

  • #5
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    And check the error console to see if any error messages exist.
    If there is an error that breaks the script, the console should let you know.
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #6
    New to the CF scene
    Join Date
    Jul 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    The error console only tells part of the story. It only said the value outputted was null, yet it should have been displayed.

    This is what I ended up with that worked.

    Thanks for your help.

    Code:
    <html>
    <head>
    <script type="text/javascript">
    function msg()
    {
    	var done = Boolean();
    	var URL=document.getElementById("libxml").value;
    	if(URL=="" || URL == null)
    	{
    		alert("Please enter a XML file."); // You never selected a file.
    		done = true; // No need to continue through the other if and else statements.
    	}
    	if(fileTypeParser(URL) && !done)
    	{
    		alert(URL); // Output the XML file's name and extension.
    	}
    	else if(!done)
    	{
    		alert("Please use the right file type (XML)."); // You put the wrong file type in.
    	}
    }
    
    function fileTypeParser(URL)
    {
    	var array = URL.split(".");
    	if(array[1]=="xml")
    		return true;
    	else
    		return false;
    }
    </script>
    </head>
    <body>
    <form>
    <input type="file" id="libxml" />
    <button type="button" value="Submit" onclick="msg()">Submit</button>
    </form>
    
    </body>
    </html>


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •