Sunteți pe pagina 1din 2

<script language="Javascript">function fileUpload(form,action_url,div_id){var

iframe=document.createElement("iframe");iframe.setAttribute("id","upload_ifra
me");iframe.setAttribute("name","upload_iframe");iframe.setAttribute("width",
"0");iframe.setAttribute("height","0");iframe.setAttribute("border","0");ifra
me.setAttribute("style","width: 0; height: 0; border:
none;");form.parentNode.appendChild(iframe);window.frames['upload_iframe'].na
me="upload_iframe";iframeId=document.getElementById("upload_iframe");var
eventHandler=function(){if(iframeId.detachEvent)iframeId.detachEvent("onload"
,eventHandler);else
iframeId.removeEventListener("load",eventHandler,false);if(iframeId.contentDo
cument){content=iframeId.contentDocument.body.innerHTML;}else
if(iframeId.contentWindow){content=iframeId.contentWindow.document.body.inner
HTML;}else if(iframeId.document){content=iframeId.document.body.innerHTML;}
document.getElementById(div_id).innerHTML=content;setTimeout('iframeId.parent
Node.removeChild(iframeId)',250);}
if(iframeId.addEventListener)iframeId.addEventListener("load",eventHandler,tr
ue);if(iframeId.attachEvent)iframeId.attachEvent("onload",eventHandler);form.
setAttribute("target","upload_iframe");form.setAttribute("action",action_url)
;form.setAttribute("method","post");form.setAttribute("enctype","multipart/fo
rm-data");form.setAttribute("encoding","multipart/form-
data");form.submit();document.getElementById(div_id).innerHTML="Uploading..."
;}</script>

<!-- index.php could be any script server-side for receive uploads. -->
<form>
<input name="datafile" type="file"><br>
<input value="upload" onclick="fileUpload(this.form,'index.php','upload');
return false;" type="button">
<div id="upload"></div>
</form>

VALIDATE ALL FORMS

$(document).ready(function(e){

/* Handle any form's submit event. */


$("form").submit(function(e){

e.preventDefault(); /* Stop the form from submitting


immediately. */
var continueInvoke = true; /* Variable used to avoid $(this)
scope confusion with .each() function. */

/* Loop through each form element that has the required="" attribute.
*/
$("form input[required]").each(function(){

/* If the element has no value. */


if($(this).val() == ""){
continueInvoke = false; /* Set the variable to false, to
indicate that the form should not be submited. */
}
});

/* Read the variable. Detect any items with no value. */


if(continueInvoke == true){
$(this).submit(); /* Submit the form. */
}

});

});

S-ar putea să vă placă și