Click here to Skip to main content
15,886,110 members
Home / Discussions / JavaScript
   

JavaScript

 
GeneralRe: JQuery,JavaScript,Angular JS Pin
Sunasara Imdadhusen12-Oct-14 23:36
professionalSunasara Imdadhusen12-Oct-14 23:36 
AnswerRe: JQuery,JavaScript,Angular JS Pin
Member 1111420827-Sep-14 6:43
Member 1111420827-Sep-14 6:43 
GeneralRe: JQuery,JavaScript,Angular JS Pin
Sibeesh KV27-Sep-14 7:50
professionalSibeesh KV27-Sep-14 7:50 
QuestionConverting an URL to JSON encoded format Pin
jasonalien9-Sep-14 3:32
jasonalien9-Sep-14 3:32 
AnswerRe: Converting an URL to JSON encoded format Pin
Dennis E White9-Sep-14 5:00
professionalDennis E White9-Sep-14 5:00 
GeneralRe: Converting an URL to JSON encoded format Pin
jasonalien9-Sep-14 20:24
jasonalien9-Sep-14 20:24 
AnswerRe: Converting an URL to JSON encoded format Pin
MIG77711-Oct-14 6:48
MIG77711-Oct-14 6:48 
QuestionValidate and submit a form containing data and a file using ajax/jquery Pin
Member 109499861-Sep-14 10:41
Member 109499861-Sep-14 10:41 
XML
I have a form containing data and a file input fields,
I want to submit and validate this form using jquery and ajax through one script.

Below is my form:

    <form id="datas" method="post" enctype="multipart/form-data">
        <input type="text" name="firstName" value="" />
        <input name="pic" type="file" />
        <button>Submit</button>
    </form>

Now I have this code to validate the data

    $('#datas').validate({
        rules: {
            firstName:{
                required: true,
                minlength: 2,
                maxlength: 100
            }

        },
        messages: {
            firstName: {
                required: "Please Enter first name",
                minlength: jQuery.format("Enter at least {0} characters"),
                maxlength: jQuery.format("Enter atmost {0} characters"),
            }
        }
    });

Then I have a seperate code that could submit the form

    $("#datas").submit(function(){

        var formData = new FormData($(this)[0]);

        $.ajax({
            url: sucess.php,
            type: 'POST',
            data: formData,
            async: false,
            success: function (data) {
                alert(data)
            },
            cache: false,
            contentType: false,
            processData: false
        });
    });


**QUESTION:**

Please how can I combine these two scripts to validate the file and data fields and also submit to the success page.

AnswerRe: Validate and submit a form containing data and a file using ajax/jquery Pin
Dennis E White3-Sep-14 4:38
professionalDennis E White3-Sep-14 4:38 
GeneralRe: Validate and submit a form containing data and a file using ajax/jquery Pin
Sunasara Imdadhusen3-Sep-14 21:03
professionalSunasara Imdadhusen3-Sep-14 21:03 
AnswerRe: Validate and submit a form containing data and a file using ajax/jquery Pin
jkirkerx16-Sep-14 11:35
professionaljkirkerx16-Sep-14 11:35 
QuestionFiltering search results the Google's way Pin
Member 1103422329-Aug-14 19:45
Member 1103422329-Aug-14 19:45 
AnswerRe: Filtering search results the Google's way Pin
Richard MacCutchan29-Aug-14 23:04
mveRichard MacCutchan29-Aug-14 23:04 
GeneralRe: Filtering search results the Google's way Pin
Member 1103422330-Aug-14 3:07
Member 1103422330-Aug-14 3:07 
GeneralRe: Filtering search results the Google's way Pin
Richard Deeming1-Sep-14 2:10
mveRichard Deeming1-Sep-14 2:10 
GeneralRe: Filtering search results the Google's way Pin
Simon_Whale1-Sep-14 3:14
Simon_Whale1-Sep-14 3:14 
AnswerRe: Filtering search results the Google's way Pin
Sibeesh KV23-Sep-14 19:13
professionalSibeesh KV23-Sep-14 19:13 
Questionfancy box popup Pin
beginerbuddy28-Aug-14 9:18
beginerbuddy28-Aug-14 9:18 
QuestionRe: fancy box popup Pin
ZurdoDev28-Aug-14 9:46
professionalZurdoDev28-Aug-14 9:46 
AnswerRe: fancy box popup Pin
ZurdoDev28-Aug-14 9:47
professionalZurdoDev28-Aug-14 9:47 
GeneralRe: fancy box popup Pin
Sunasara Imdadhusen3-Sep-14 21:06
professionalSunasara Imdadhusen3-Sep-14 21:06 
AnswerRe: fancy box popup Pin
Sibeesh KV23-Sep-14 19:16
professionalSibeesh KV23-Sep-14 19:16 
QuestionCode I don't understand. Pin
ChicagoBobT28-Aug-14 7:54
ChicagoBobT28-Aug-14 7:54 
AnswerRe: Code I don't understand. Pin
Graham Breach28-Aug-14 8:58
Graham Breach28-Aug-14 8:58 
GeneralRe: Code I don't understand. Pin
ChicagoBobT28-Aug-14 11:08
ChicagoBobT28-Aug-14 11:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.