i have html code and jquery to show and hide a form based on image loaded or not loaded like this
...
<title>Untitled Document</title>
</head>
<script type="text/javascript" src="bootstrap/js/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#image11")
.load(function(){
alert('oke1');
$("#upload1").hide();
$("#image21").hide();
})
.error(function(){
alert('oke2');
$("#image11").hide();
$("#upload1").hide();
$("#image21")
.load(function(){
alert('oke3');
$("#upload1").hide();
$("#image11").hide();
})
.error(function(){
alert('oke4');
$("#upload1").show();
$("#image21").hide()
$("#image11").hide();
});
});
})
</script>
<body>
<div class="col-sm-5 col-xs-7">
<img src="foto_peserta/tes.jpg" width="100" id="image11" alt="tes"/>
<img src="foto_peserta/cek.jpg" width="100" id="image21" alt="tes2"/>
</div>
<div id="upload1">
<form method="post" name="form1" action="<?php echo $editFormAction; ?>" enctype="multipart/form-data"><img id="previewHolder" alt="Foto" width="100px" height="100px"/> <p>
<input type="file" name="foto_peserta" id="foto_peserta" required>
<p class="help-block">maximum image size is 50 kB,only JPG, JPEG, PNG & GIF files are allowed</p>
<button type="submit" class="btn btn-success">Upload Foto</button>
<input type="hidden" name="MM_update" value="form1" >
<input type="hidden" name="id_personal" value="<?php echo $row_foto_peserta_tampil['id_personal']; ?> ">
</form></div>
</body>
</html>
I just confused why every time i refresh the page (when my image21 is load and my image11 not loaded) the alert ('oke2')
prompt but not with alert('oke3')
, is anything wrong with my code?