DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Frank Y. Guest

    about client side validation


    Hi all,
    I want to do a client side form validation before it is submitted.
    The form looks like the following:

    <FORM NAME=UPLFORM ACTION="/km/index/userupload.asp?" METHOD="POST"
    ENCTYPE="multipart/form-data"> Please select a file:<br />
    <INPUT TYPE=FILE SIZE=36 NAME="uplfile"><BR>
    <INPUT TYPE=SUBMIT NAME="SUBMIT" VALUE="Upload">
    </FORM>

    I want to check if the user has actually selected a file. How?

    Thanks a lot


  2. #2
    Stuart Guest

    Re: about client side validation


    Try this Frank,

    Insert the following code between the <head> tags -

    <script language="JavaScript">
    function CheckForm (aform)
    {
    if (aform.uplfile.value == "")
    {
    alert ("Please Select a file to upload!");
    }
    return !(aform.uplfile.value == "");
    }
    </script>

    And add the following onSubmit to the <form> tag -

    <FORM NAME=UPLFORM ACTION="/km/index/userupload.asp?" METHOD="POST" ENCTYPE="multipart/form-data"
    onSubmit="javascript:return CheckForm(this);">


    Hope it helps.

    Feel free to contact me is you have any trouble,

    Stuart.

    "Frank Y." <yangyuchen39@hotmail.com> wrote:
    >
    >Hi all,
    >I want to do a client side form validation before it is submitted.
    >The form looks like the following:
    >
    ><FORM NAME=UPLFORM ACTION="/km/index/userupload.asp?" METHOD="POST"
    > ENCTYPE="multipart/form-data"> Please select a file:<br />
    > <INPUT TYPE=FILE SIZE=36 NAME="uplfile"><BR>
    > <INPUT TYPE=SUBMIT NAME="SUBMIT" VALUE="Upload">
    ></FORM>
    >
    >I want to check if the user has actually selected a file. How?
    >
    >Thanks a lot
    >



  3. #3
    Davis Guest

    Re: about client side validation


    It seems the file controller can input text by hand.

    "Stuart" <stuartv@prologic.com.au> wrote:
    >
    >Try this Frank,
    >
    >Insert the following code between the <head> tags -
    >
    ><script language="JavaScript">
    >function CheckForm (aform)
    >{
    > if (aform.uplfile.value == "")
    > {
    > alert ("Please Select a file to upload!");
    > }
    > return !(aform.uplfile.value == "");
    >}
    ></script>
    >
    >And add the following onSubmit to the <form> tag -
    >
    ><FORM NAME=UPLFORM ACTION="/km/index/userupload.asp?" METHOD="POST" ENCTYPE="multipart/form-data"
    >onSubmit="javascript:return CheckForm(this);">
    >
    >
    >Hope it helps.
    >
    >Feel free to contact me is you have any trouble,
    >
    >Stuart.
    >
    >"Frank Y." <yangyuchen39@hotmail.com> wrote:
    >>
    >>Hi all,
    >>I want to do a client side form validation before it is submitted.
    >>The form looks like the following:
    >>
    >><FORM NAME=UPLFORM ACTION="/km/index/userupload.asp?" METHOD="POST"
    >> ENCTYPE="multipart/form-data"> Please select a file:<br />
    >> <INPUT TYPE=FILE SIZE=36 NAME="uplfile"><BR>
    >> <INPUT TYPE=SUBMIT NAME="SUBMIT" VALUE="Upload">
    >></FORM>
    >>
    >>I want to check if the user has actually selected a file. How?
    >>
    >>Thanks a lot
    >>

    >



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links