Home  • Online Tips • VCampus Help
how to write document/form values to a new window with javascript(most simplest way)

Comments 8


<!DOCTYPE html>
<head>
<title>Student Admission</title>
<script language="javascript">

function dyn_window(){	
	
	var title="My Title";
	
	var name=document.f.txtName.value;
	var address=document.f.txtAddress.value;
	var course=document.f.txtCourse.value;
	var sex="";
	var subject="";
	
 
	for (i=0;i<document.f.rdoSex.length;i++) {
	   if (document.f.rdoSex[i].checked) {
		sex = document.f.rdoSex[i].value;
	  }
       }
	
  for(j=0;j<document.f.chkSubject.length;j++){
	
    if (document.f.chkSubject[j].checked) {
	        subject+=document.f.chkSubject[j].value+", ";
    }
  }	

   // creating new window here
	
    a=window.open('','','width=300,height=300');
	
	a.document.write("<html>");
	a.document.write("<head><title>"+title+"</title></head>");
	a.document.write("<body>");
	
	a.document.write("Name:"+name+"<br/>");
	a.document.write("Address:"+address+"<br/>");
	a.document.write("Course:"+course+"<br/>");
	a.document.write("Sex:"+sex+"<br/>");
	a.document.write("Subject:"+subject+"<br/>");
	a.document.write("<input type='button' value='Close me' onclick='self.close();' />");
	
	a.document.write("</body>");
	a.document.write("</html>");
	 
}// end the function 

</script>
</head>

<body>
<form action="#" method="post" name="f" style="width:200px; margin:0px auto; border:1px solid gray; padding:10px">
  
  <div>Name<br/>
  <input type="text" name="txtName" />
  </div>
  
  <div>Address<br/>
  <textarea  name="txtAddress" ></textarea>
  </div>
  
  <div>Course<br/>
  <select name="txtCourse" >
    <option value="MBA">MBA</option>
    <option value="BBA">BBA</option>
    <option value="CIS">CIS</option>
    <option value="EEE">EEE</option>
  </select>
  </div>
  
  <div>Sex<br/>
   Male<input type="radio" name="rdoSex" value="Male" />
   Female<input type="radio" name="rdoSex" value="Female" />  
  </div>
  
  <div>Subject<br/>
   English<input type="checkbox" value="English" name="chkSubject" />
   Bengali<input type="checkbox" value="Bengali" name="chkSubject" />
  </div>
  
  <div>
  <input type="button" onclick="dyn_window()" value="Submit" />
  </div>
</form>
</body>
</html>
I can't thank you enough for your kind support. it is too hard for me and too big for a beginer, i guess! how do i cut short it for quick learning?
Assuming that you have just finished IDB-BISEW javascript module from any TSP to understand.
Otherwise it will be difficult to you
To understand the above code you have to be experienced on how to define function,use of DOM and HTML.
@Boby: Dr. Boby, it is your lack not to knowing them clearly, but it is core and plain javascript and Towhid should be thanked,
I would love to suggest you to read "The Complete Reference of Javascript" By McGrawhill publication, where McGrawhill(Software Engineer (Google)) and Sir Herbert schieltz will be your friend to grab a better undestand. Take your time until u have completed first (probarbly) 8 chap. Than take a look on those code,Though u r a beginner, but u will be a pro, if you can tolerate untill the time,

Share

About Author
Md Boby
Copyright © 2024. Powered by Intellect Software Ltd