0

i have this problem: i have this code

if(ext!="rar") {
$('#myform').trigger('click');
}

and if the file extension of the chosen file is not rar, the file input should open the window again to choose another file, but this code does not seem to work. What should i do?

2 Answers2

0
$("#btn").click(function()
{    
    var fu = $("#fu");
    var ext = /[^.]+$/.exec(fu.val());
    if (ext!="rar")
    {
        fu.trigger("click");
    }
});

http://jsfiddle.net/tugpM/1/

Hanlet Escaño
  • 17,114
  • 8
  • 52
  • 75
-1

Assuming that your form tag has the id myform, what you have done just triggers a click on the form (not even on the submit button of the form). Without the HTML, it is not possible to know what you are triggering the click on.

What you need to do is trigger the click on the submit button

$('#mysubmitbutton').click();

or trigger a form submit:

$('#myform').submit();
cssyphus
  • 37,875
  • 18
  • 96
  • 111
  • What i nees is if the filetype is not rar, the upload form should open again. I do not want to submit anything until the user has chosen a rar file – George Lazu Aug 17 '13 at 08:20
  • Then you must make a new question (since this one was closed) and ask that question specifically. You want to ask "How do I determine if user is uploading correct file type before submitting" – cssyphus Aug 17 '13 at 19:41