Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 03-27-2005, 09:22 AM   #1 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,470
sde is on a distinguished road
javascript: check if file input is undefined

I need to check if a file input box is undefined, but I can not get this to work.

If I alert(document.lform.logoimage.value); , it pops up: "undefined"

So I have tried to evaluate that field to "undefined" and "", and neither work.

so how can I check if a file is not there? i only want this confirmation box to pop up if the user has chosen a file to upload. ( there are other text elements on the form )
HTML Code:
<Script language="JavaScript">
<!--
function verifyLogo(){
  
  if( document.lform.logoimage.value !=  "" ){
    var c = confirm("Are you sure you want to replace the logo image?\nThe current image will be deleted.");
    if( c ){
      return true ;
    }else{
      return false ;
    }
  }
  return true ;
}
-->
</script>
__________________
Mike
sde is offline   Reply With Quote
Old 03-27-2005, 06:11 PM   #2 (permalink)
idx
Senior Grasshopper
 
idx's Avatar
 
Join Date: Jun 2003
Location: FL
Posts: 317
idx is on a distinguished road
I'll have to check, but you might be out of luck. The file upload boxes are pretty limited JS-wise due to obvious security issues, but it seems like you could at least check the value on the client-side..

-r
idx is offline   Reply With Quote
Old 03-27-2005, 06:16 PM   #3 (permalink)
idx
Senior Grasshopper
 
idx's Avatar
 
Join Date: Jun 2003
Location: FL
Posts: 317
idx is on a distinguished road
hrm.. works for me. eg:

Code:
<script>
<!--
  function check_form(form) {

     if (form.foo.value == "") {
        alert("foo is required!");
        form.foo.focus();
        return false;
     }

     return true;
  }

//-->
</script>

<form name="me" action="<?=$_SERVER['PHP_SELF']?>" method="POST" onsubmit="return check_form(this);">

<input type="file" name="foo">
<input type="submit">
</form>
idx is offline   Reply With Quote
Old 03-28-2005, 08:15 AM   #4 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,470
sde is on a distinguished road
cool thanks! .. i wasn't sending it the form as the argument.
__________________
Mike
sde is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Text file input to an array letsC Standard C, C++ 9 03-06-2005 09:30 AM
dynamic allocation..urgent help needed!!! kashif Standard C, C++ 4 04-21-2003 08:50 AM


All times are GMT -8. The time now is 07:37 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting