Saturday, December 5, 2015

form validation with html and javascript lab

<html>
<head>
  <title>Html form validation</title>
  <script type="text/javascript" src="java.js">
  </script>
</head>
<body>

  <center>
    <form class="forms">
      User Name * <input type="text" id="uname" placeholder="Username">
      <br>
      Password  * <input type="password" id="pass" placeholder="password">
      <br>
      Cell No <input type="text" id="cell" placeholder="Cellno">
       <br>
      Email <input type="text" id="email" placeholder="Email">
      <br>

      Country

      <select>
        <option value="Nepal">Nepal</option>
        <option value="USA">USA</option>
        <option value="UK">UK</option>
        <option value="China">China</option>
      </select>

      <br>

      Sex
      <input type="radio" name="sex" value="male">
      <input type="radio" name="sex" value="female">

      <input type="submit" onclick="formValidation()" value="submit">

    </form>
  </center>
</body>
</html>

Save this with form.html file

 

function formValidation()
{

   
    var cell = document.getElementById("cell").value;
    if(cell.length == 0)
    {
        alert("Enter cell");
        document.getElementById("cell").focus();
    }
   
    var cellpat = /^[0-9]+$/;
    if(cell.match(cellpat))
    {    alert("valid entry");}
    else
    {
        alert("Enter Valid cell");
        document.getElementById("cell").focus();
    }
   

Save this with java.js 

Wednesday, December 2, 2015

Simple HTML form for web technology lab

<html>
<head>
  <title>Html form validation</title>
  <script type="text/javascript">
  </script>
</head>
<body>

  <center>
    <form class="forms">
      User Name * <input type="text" placeholder="Username">
      <br>
      Password  * <input type="password" placeholder="password">
      <br>

      Country

      <select>
        <option value="Nepal">Nepal</option>
        <option value="USA">USA</option>
        <option value="UK">UK</option>
        <option value="China">China</option>
      </select>

      <br>

      Sex
      <input type="radio" name="sex" value="male">
      <input type="radio" name="sex" value="female">

      <input type="submit" value="submit">

    </form>
  </center>
</body>
</html>