2012-08-28 43 views
0
if(isset($_POST['album_title'])) { 
$album_title = $_POST['album_title']; 
if($_FILES['pic_nr1']['type'] == 'image/jpeg' || 
    $_FILES['pic_nr1']['type'] == 'image/jpg' || 
    $_FILES['pic_nr1']['type'] == 'image/png' || 
    $_FILES['pic_nr1']['type'] == 'image/gif' & 

    $_FILES['pic_nr2']['type'] == 'image/jpeg' || 
    $_FILES['pic_nr2']['type'] == 'image/jpg' || 
    $_FILES['pic_nr2']['type'] == 'image/png' || 
    $_FILES['pic_nr2']['type'] == 'image/gif' & 

    $_FILES['pic_nr3']['type'] == 'image/jpeg' || 
    $_FILES['pic_nr3']['type'] == 'image/jpg' || 
    $_FILES['pic_nr3']['type'] == 'image/png' || 
    $_FILES['pic_nr3']['type'] == 'image/gif' 
    ) { 

    } else { 
?> 
<script type="text/javascript"> 
    document.getElementById("error_for_js").innerHTML = "Bilžu formāts nav derīgs! <small> GIF, JPEG, JPG, PNG ir autļauti.</small>"; 
</script> 
<?php 

    } 

} 
?> 


<form enctype="multipart/form-data" method='post' action='' onsubmit='if(document.getElementById("titleeee").value.length < 3) { document.getElementById("error_for_js").innerHTML = "Albūma nosaukumam ir jābūt garākam!"; return false; } else { return true; }' > 
    <p id='error_for_js'></p> 
    Albūma nosaukums: <input id='titleeee' type='text' name='album_title' /><br /> 

    Bilde Nr 1: <input type='file' name='pic_nr1' /><br /> 
    Bilde Nr 2: <input type='file' name='pic_nr2' /><br /> 
    Bilde Nr 3: <input type='file' name='pic_nr2' /><br /> 

    Aktīvs*: <select> 
       <option>Jā</option> 
       <option>Nē</option> 
      </select><br /> 
    <input type='submit' value='Pievienot' /> 
</form> 

我不明白为什么id='error_for_js'价值不改变,如果文件格式是错误的,我做的getElementById('error_for_js').innerHTML = 'new value';但它没有改变!?想法?JavaScript值变化

+0

在文档被解析之前,您正在设置'p'标记的值。 – jbabey

+0

你的PHP条件表达式并不像你想象的那样工作,'&'运算符比'||'具有更高的优先级 - 添加一些括号 – Bergi

+0

您不应该为该任务使用JavaScript。你为什么不直接用PHP回应html? – Bergi

回答

2

包装你的getElementById有:

window.onload = function() { 
    document.getElementById("error_for_js").innerHTML = "Hello!"; 
}; 

或HTML元素后添加脚本。