Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
130 views
in Technique[技术] by (71.8m points)

JAVASCRIPT-FORM

User must be able to insert name,address,gender,stream and module....when user clicks the clear button,the form should be cleared, and when user clicks the Ok Button,the name and address should be displayed below the form..

Problem: Clear button doesn't work properly.how can i correct it??

Application.htm

<!DOCTYPE html>
<html>
 <head>
 <script type="text/javascript" src="ApplicationForm.js"></script>
 </head>


 <body>
<form id="frm1">
            <!-----Application Table ---->
<table cellpadding="8">
<tr>
                 <td>Name</td>
                 <td><input type="text" id="txtName" size=30 value=" "></td>
           </tr>

<tr>
                 <td> Address</td>
                 <td><input type="text" id="txtAdd" size=30 value=" "></td>
           </tr> 

<tr>
                 <td>Gender</td>
                 <td><input type="radio" name="sex" value="M"> Male
                         <input type="radio" name="sex" value="F"> Female </td>
</tr>

<tr>
                  <td>Stream </td>
                  <td><select name="stream">
      <option id="0" value="0">---Select stream---</option>
      <option id="1" value="se">SE</option>
                  <option id="2" value="isbm">ISBM</option>
                  </select><br  /> </td>
</tr>

<tr>
      <td>Modules</td>
      <td><input type="checkbox" name="module" value="m1"> M1
                          <input type="checkbox" name="module" value="m2"> M2
              <input type="checkbox" name="module" value="m3"> M3
                          <input type="checkbox" name="module" value="m4"> M4 

</td>
</tr>

            <tr>
     <td><input type="button" name="submit" value="OK" onclick="clickOk()">
                         <input type="button" name="reset" value="Clear" 
                           onclick="formReset()"></td>
           </tr>



</table>
</form>
       <div id="display"></div>

 </body>
</html>

ApplicationForm.js

function clickOk(){

  if(document.getElementById("txtName").value!=" "){

              if(document.getElementById("txtAdd").value!=" "){

                   var nam=document.getElementById("txtName").value;
                   var add=document.getElementById("txtAdd").value;

              document.getElementById("display").innerHTML="<hr>Hi 
             "+nam+"<br>Address: "+add;
                        }

              else 
                   alert("Please enter your Address");
              }

else 
         alert("Please enter your Name");
}


function formReset()
{
document.getElementById("frm1").reset();
}  
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
<input type="reset" name="reset" value="Clear">

is all that you need to do.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...