Javascript comme langage de scripts clients
Transcription
Javascript comme langage de scripts clients
Langage de script qui n'a de commun avec Java que le nom ! Permet d'intégrer du code dans une page HTML qui sera exécuté par le navigateur (suppose que le navigateur sache le faire et qu'on l'y autorise) Contient les constructions classiques de programmation (variables, conditionnelles, itérations, fonctions et procédures, ...) Des restrictions dues à la sécurité (pas d'accès au système de fichier local p.e) <html><head><title>INTERROGATION QBE D'UNE RELATION</title></head> <body bgcolor='#ddddfa'><hr> <script language="Javascript"> function modif(attribut){ var i; var temp; temp=""; i=0; if (attribut=="") { return(""); } if (attribut.charAt(0)!='=' &&attribut.charAt(0)!='<' && attribut.charAt(0)!='>' && attribut.charAt(0)!='!'){ attribut='=' + attribut; } while (attribut.charAt(i)=='=' || attribut.charAt(i)=='<' || attribut.charAt(i) == '>' || attribut.charAt(i) == '!') { temp=temp+attribut.charAt(i); i=i+1; } if (attribut.charAt(i)!="'") { temp=temp+"'";} while (i < attribut.length ){ temp=temp+attribut.charAt(i); i=i+1; } if (attribut.charAt(i-1)!="'") { temp=temp+"'" }; return(temp); } <FORM function check(form){ var nb; nb=0; form.where.value=" where "; if (form.NUM.value!=""){ if (nb==0) { form.where.value+="NUM"+modif(form.NUM.value); else{ form.where.value+=" and "+"NUM"+modif(form.NUM.value); nb=nb+1; } if (nb==0) { form.where.value=""; } } </script> <input <input <input <input <input } action="http://mica/cgi-bin/multi2.cgi" target="resultat" method="GET" name="fqbe"> type="hidden" name="uid" value="citcom/citcom@MICA"> type="hidden" name="mode" value="NOR"> type="hidden" name="temp" value="select * from VINS"> type="hidden" name="sqlstatement" value=""> type="hidden" name="where" value=""> <table border> <caption align="top"><b>INTERROGATION QBE D'UNE RELATION</b></caption> <tr><td>NUM</td></tr> <tr><td><input name="NUM" size="26"></td></tr> </table> <input type="button" value="interroger" onClick="check(fqbe); fqbe.sqlstatement.value = fqbe.temp.value+fqbe.where.value; fqbe.submit();"> <input type="reset" value="effacer"> </form> </body></html> Applications BD/Web - 1