简体   繁体   中英

nothing happens when click on a form html button

Following the transition from a Windows environment to Linux and modernise a code. I meet a new problem. I send a csv file. But when i click on the button in order to handle it, nothing happens

<?php
echo "<form enctype=\"multipart/form-data\" id=\"form_impmat\" 
name=\"form_impmat\" action=\"\" method=\"post\">\n";
....
echo "<p><input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"1000000\" 
/>\n
            Fichier au format CSV : <input name=\"userfile\" type=\"file\" 
style=\"border:1px solid #CCCCCC;\" />\n
            <a href=\"javascript:valid_form();\" title=\"Envoyer le 
fichier\" class=\"submit\">Envoyer le fichier</a></p>\n</form>";
?>

I think that the problem is in the javascript :

<script type="text/javascript">

function valid_form() {

if(document.layers) {
    form = document.layers('form_impmat');
}
//IE6
if(document.all) {
    form = document.all('form_impmat') ;
}
//Netscape 6
if(!document.all && document.getElementById) {
    form = document.getElementById('form_impmat') ;
}

var valid = false;

if (form.ORDER_DETAILS_ID.length != null) {
    for (var i=0 ; i < form.ORDER_DETAILS_ID.length ; i++) {

        if (form.ORDER_DETAILS_ID[i].checked) {

            valid = true;
        }
    }
} else {
    if(form.ORDER_DETAILS_ID.checked)
        valid = true;
}


var message = "";
if (form.userfile.value == "") message += "Vous n'avez spécifié aucun 
fichier !\n";
if(!valid) message += "Vous n\'avez pas choisi de commande !\n";

if (message != "") alert('Opération annulée!\n\n'+message);
else form.submit();


}
</script>

Nothing happens but in the old version, the csv file is handled

You're trying to include a string on two lines but JavaScript does not support that. Change

if (form.userfile.value == "") message += "Vous n'avez spécifié aucun 
fichier !\n";

to

if (form.userfile.value == ""){
    message += "Vous n'avez spécifié aucun fichier !\n";
}

In future, you can figure out whether the request is sending or it is a JavaScript error by right clicking the webpage and viewing "inspect element" as in Chrome or something similar. It shows you if there are any JavaScript errors and what, if anything, JavaScript sent to a server.

If you want to get advanced, there is also this: Creating multiline strings in JavaScript

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM