Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-11-2012, 03:17 PM   PM User | #1
flapjacksmike
New to the CF scene

 
Join Date: Jul 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
flapjacksmike is an unknown quantity at this point
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.
flapjacksmike is offline   Reply With Quote
Old 07-11-2012, 03:43 PM   PM User | #2
WolfShade
Regular Coder

 
Join Date: Apr 2012
Location: St. Louis, MO, USA
Posts: 946
Thanks: 7
Thanked 97 Times in 97 Posts
WolfShade is an unknown quantity at this point
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".
WolfShade is offline   Reply With Quote
Old 07-11-2012, 03:43 PM   PM User | #3
DrDOS
Senior Coder

 
Join Date: Sep 2010
Posts: 1,155
Thanks: 10
Thanked 148 Times in 148 Posts
DrDOS is infamous around these parts
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.
DrDOS is offline   Reply With Quote
Old 07-11-2012, 04:32 PM   PM User | #4
flapjacksmike
New to the CF scene

 
Join Date: Jul 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
flapjacksmike is an unknown quantity at this point
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.
flapjacksmike is offline   Reply With Quote
Old 07-11-2012, 04:37 PM   PM User | #5
WolfShade
Regular Coder

 
Join Date: Apr 2012
Location: St. Louis, MO, USA
Posts: 946
Thanks: 7
Thanked 97 Times in 97 Posts
WolfShade is an unknown quantity at this point
Quote:
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".
WolfShade is offline   Reply With Quote
Old 07-11-2012, 05:11 PM   PM User | #6
flapjacksmike
New to the CF scene

 
Join Date: Jul 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
flapjacksmike is an unknown quantity at this point
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>
flapjacksmike is offline   Reply With Quote
Reply

Bookmarks

Tags
alert, form, javascript, xml

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:16 PM.


Advertisement
Log in to turn off these ads.