views:

57

answers:

2

So, this is strange, and it was working for me about a month ago, before I made a bunch of code updates. Anyways the issue is the live submit handler wont even run in IE8, however, if i run it on a button click, it works. See below:

HTML

        <label>Add Attachment</label>
        <form class="file_upload" method="post" enctype="multipart/form-data" target="upload_target" action="">
            <input name="binary" id="file" size="27" type="file" /><br />
            <br><input type="submit" name="action" value="Upload" /><br />
            <input type="button" class="test" value="test">
            <iframe class="upload_target" name="upload_target" src="" style=""></iframe>
        </form>
        <label>Attachments</label>
        <ul class="upload_output">
        <li class="nofiles">(No Files Added, Yet)</li>
        </ul>

JavaScript:

function file_upload($theform,item_id){
    $theform.attr('ACTION','io.cfm?action=updateitemfile&item_id='+item_id);
    if($theform.find('[type=file]').val().length > 0){
        $('iframe').one('load',function(){
            $livepreview.agenda({
                action:'get',
                id:item_id,
                type:'item',
                callback:function(json){
                    $theform.siblings('.upload_output').append('<li style="display:none" class="file-upload"><a target="blank" href="io.cfm?action=getitemfile&item_file_id='+json[0].files.slice(-1)[0].item_file_id+'">'+json[0].files.slice(-1)[0].file_name+'</a> <a style="color:red" title="Delete file?" href="#deletefile-'+json[0].files.slice(-1)[0].item_file_id+'">[X]</a></li>').children('li').fadeIn();
                    $theform.siblings('.upload_output').find('.nofiles').remove();
                }
            });
            //Resets the file input. The only way to get it cross browser compatible as resetting the val to nothing
            //Doesn't work in IE8. It ignores val('') to reset it.
            $theform.append('<input type="reset" style="display:none">').children('[type=reset]').click().remove();
        });
    }
    else{
        $.alert('No file selected');
        return false;
    }
}
/* FILE UPLOAD EVENTS */
//When they select "upload" in the modal
$('.file_upload').live('submit',function(event){
    alert('hello world');
    file_upload($('.agenda-modal .file_upload'),$('.agenda-modal').attr('data-defaultitemid'));
});
/* This is the code that makes it work..., but i dont want it! it should alert hello world on the submit button! */
$('.test').live('click',function(event){
    $('.file_upload').submit();
});
A: 
  1. instead of creating reset button, emulating click event and destroying it -- why not just

    $('.file_upload').reset();
    
  2. Do you really need live to submit the form? If the button stays in the DOM all the time, make it use the normal click event like

    $('.test').click(function(){
        $('.file_upload').submit();
    });
    
lashtal
Reset didn't work in IE8 at all. Just kept it there. Trust me... i think its an ugly looking hack, but .reset() did nothing.The form isn't static. The form is automagically generated from a sort of "template" within the DOM and it's cloned and manipulated then placed inside of a modal box.
Oscar Godson
A: 

That is by design, and not at all isolated to IE 8. It has always been that way, in all browsers.

The submit event doesn't happen if you call the submit method, only when you submit the form using the submit button.

Guffa
So... how do I fix this? It was working, well, the live submit was working before I made code updates, and i can just hide the submit button and make a input type="button" button and have that click handler, its just ugly...
Oscar Godson