Search code examples
jqueryformsimpromptu

Perform form validation before Submitting - jQuery


Using jquery impromptu popup, i have made a form . But the problem is i want to check the user input before submitting. Is it possible.
In here, if the user selects options in the second screen, i want to call another popup based on its value. Is it possible.

var my_states = {
state0: {
    title: 'Name',
    html:'<label>First <input type="text" name="fname" value=""></label><br />'+
        '<label>Last <input type="text" name="lname" value=""></label><br />',
    buttons: { Next: 1 },
    //focus: "input[name='fname']",
    submit:function(e,v,m,f){ 
        console.log(f);

        e.preventDefault();
        $.prompt.goToState('state1');
    }
},
state1: {
    title: 'Check Here',
    html:'<table><tr><td><strong>Generate ODEC ID </strong></td><td>:</td><td id=\'gen_odec\' class=\'gen_odec\'>   <select name=\'select_odec\' id=\'select_odec\' class=\'select_odec\'>'+<?php echo json_encode($odecpref)?>+'</select></td></tr></table>',
    buttons: { Back: -1, Next: 1 },
    //focus: ":input:first",
    submit:function(e,v,m,f){ 
        console.log(f);

        if(v==1) {$.prompt.close();
                    return false;}
        if(v==-1) $.prompt.goToState('state0');
        e.preventDefault();
    }
},  
 };  
 $.prompt(my_states);

Solution

  • Using "on" in jQuery solves the issue------ like this . Thanks to @Roland Bertolom

    $(document).on('change', '#select_odec', function(){
    if($(this).val() === 'valueOfDesiredOption') {
        $.prompt.goToState('stateYouNeed');
    }
    

    });