Some basic javascript usage

In modern page design, JavaSricpt is quit important to do some input check at Client side.

In the comp231 project, we want to build a library management system based on Web, so JavaScript is used

Here I do some summary:

1. check whether the input of a form is Empty or not:

<SCRIPT LANGUAGE="JavaScript">
<!--
{
     if(form.name.value.length==0)
          alert("input empty");
     else
          form.submit();
}

//-->
</SCRIPT>

here, form is the name of the <form> and name is the text of pass name, in this check() the situation that all spaces in name can't be detected.

2. check whether the input is a Number or not

<SCRIPT LANGUAGE="JavaScript">
<!--
function check()
{
     if(isNaN(aaform.aa.value))
          alert("input is not a number");
     else
          alert("input is a number");
}
//-->
</SCRIPT>

3 check whether a checkbox is checked

<SCRIPT LANGUAGE="JavaScript">
<!--
function checkb()
{
     if(myform.mycheckbox.check)
          alert("checkd");
     else
          alert("not checked");
}
//-->
</SCRIPT>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章