SlideShare a Scribd company logo
Lecture 18
In this lecture, we will learn
-> Validating Radio Button

Validating Radio Button Selections
       A radio button, provide a set of options, out of which only one can be
selected. Infact, there are lot of simillarities between radio button and check box.
Except one dissimillarity, which is, check box provide a lot of options to be
selected whereas you can only select one option with radio button.

To know which option is selected, the following statement can be used

document.name of the form.name of the button[i].checked,

The above statement returns true if the button is selected otherwise false. The
value of 'i' ranges from (0 to number_of_radio_buttons - 1 ).

Let us take an example.

<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<script language="JavaScript">
function validate()
{
       number_of_radio_buttons=document.myForm.hobby.length;
       for (i=0;i<=number_of_radio_buttons-1;i++)
       {
       if (document.myForm.hobby[i].checked)
       {
                flag=1;
                you_selected=document.myForm.hobby[i].value;
                window.alert(you_selected);
                return true;
       }
       else
                flag=0;
       }
       if (flag==0)
       {
                window.alert("Error! You should select one of the options");
                return false;
       }
}
</script>
</HEAD>

<BODY>
My hobbies are
     <form method="get" action="display.asp" name="myForm"
onSubmit="return validate()">
     <input type="radio" name="hobby" value="soccer"> Soccer <br>
     <input type="radio" name="hobby" value="read"> Reading <br>
     <input type="radio" name="hobby" value="music"> Listening Music <br>
     <input type="radio" name="hobby" value="travel"> Travelling <br>

     <input type="submit" value="Validate">
     </form>
</BODY>
</HTML>

Let us summarize, what we have learned by the above program
1. To know the number of radio buttons:        document.name of form.name of
radio button.length
2. To know index of radio button selected:          document.name of
form.name of radio button[i].selected
3. To know the value of radio button selected: document.name of form.name of
radio button[i].value

Using the Window Object
       We will discuss more about the Window object. We have been already
using the Window object before.

Some of the features of Window object are
1.   Creating Alert Dialog Boxes:             window.alert()
2.   Creating Confirmation Dialog Boxes:      window.confirm()
3.   Creating Dialog Boxes to get:            window.prompt()
     information from the user.
4.   Opening Pages in new window:             window.open()
5.   Determining window size
6.   Controlling scrolling of the document displayed in window
7.   Scheduling the execution of function:    window.setTimeout()

So, we have done all this before. This is all we have to learn about window
object.
Open a Full Screen window
The following is the code to open a full screen window

<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<script language="JavaScript">
       function showWindow()
       {
              window.open("","myNewWindow","fullScreen=yes");
       }
</script>
</HEAD>
<BODY>
       <a href="a.html" onMouseOver="showWindow()" >Click1</a>
</BODY>
</HTML>

Handling the Parent-Child
Relationship of Windows
         When the window.open() method is used to open a new window from
JavaScript, a relationship exist between the original window and new window so
that it is possible to refer to both the windows from within JavaScript.

Well, to refer to the child window, simply do this

var newWindow=window.open(“URL”,window name);

Now you can refer to the new window, by newWindow.

Let us take an example

<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<script language="JavaScript">
       function showWindow()
       {
              myNewWindow=window.open("","myNewWindow");

       }

       function closeWindow()
{
            myNewWindow.close();
      }

       function closeThisWindow()
       {
              window.close();
       }
</script>
</HEAD>
<BODY>
       <a href="" onMouseOver="showWindow()" >Take the Mouse here to open
a New window</a> <br>
       <a href="" onMouseOver='closeWindow()' >Take the Mouse here to close
the Opened Window</a><br>
       <a href="" onMouseOver="closeThisWindow()">Take the Mouse here to
close this Window</a>
</BODY>
</HTML>

Let us take another example, where you will open a new window. The new
window have the option for closing the parent window.

<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<script language="JavaScript">
       function showWindow()
       {
              myNewWindow=window.open("a.html","myNewWindow");

      }

      function closeWindow()
      {
             myNewWindow.close();
      }

       function closeThisWindow()
       {
              window.close();
       }
</script>
</HEAD>
<BODY>
       <a href="" onMouseOver="showWindow()" >Take the Mouse here to open
a New window</a> <br>

</BODY>
</HTML>

Here is the code for a.html

<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<script language="JavaScript">
       function closeOriginalWindow()
       {
              window.opener.close();
       }
</script>
</HEAD>

<BODY>
     <a href="" onMouseOver="closeOriginalWindow()">close the original
Window</a>
</BODY>
</HTML>

Writing into New Window

Below is the code, to write into new Window

<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<script language="JavaScript">
       function showWindow()
       {
              myNewWindow=window.open("","myNewWindow","width=200,
height=200, left=20, top=50");
              myNewWindow.document.open();
              myNewWindow.document.write("Take your mouse here to open
new window");
              myNewWindow.document.close();

      }

      function closeWindow()
      {
             myNewWindow.close();
}

       function closeThisWindow()
       {
              window.close();
       }
</script>
</HEAD>
<BODY>
       <a href="" onMouseOver="showWindow()" >Take the Mouse here to open
a New window</a> <br>

</BODY>
</HTML>

Referring Frames In JavaScript
If there are two frames on one page, name of left frame is frame1, and name of
right frame is frame2,
Then frame1 can be referred in JavaScript as parent.frame1 and similarly,
frame2 can be referred as paraent.frame2.

Let us take an example, first make frameset.html, which contains two frames,
frame1 and frame2.

<frameset cols=”50%,50%”>
      <frame name=”frame1” src=”frame1.html”>
      <frame name=”frame2” src=”frame2.html”>
</framesest>

Here is the code for frame1.html

<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<script language="JavaScript">
       function writeFrame2()
       {
              parent.frame2.document.open();

       parent.frame2.document.write(document.forms[0].f1text.value);
              parent.frame2.document.close();
       }
</script>
</HEAD>
<BODY>
<form>
<input type="text" name="f1text">
<input type="button" value="Write this to Frame 2" onClick="writeFrame2()">
<form>
</BODY>
</HTML>

To understand more about Frame object, Let me compare Frame object with
Window object. In the previous topic, we saw that, window can use the document
object, for ex. window.document.open(), Simmilarly, we can say
frame.document.open(), and then can write into the frame, as you can see in the
abov example. Infact we can use all the functions provided by the document
object.
So, the moral of the story is "Frame object contain a document object".

Let us take another simple example

This is the code for frameset.html

<frameset cols=”50%,50%”>
      <frame name=”frame1” src=”frame1.html”>
      <frame name=”frame2” src=””>
</framesest>

Notice that, source for frame2 doesnot exist

Below is the code for frame1.html

<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<script language="JavaScript">
       function writeFrame2()
       {
              parent.frame2.document.location=document.forms[0].f1text.value;
       }
</script>
</HEAD>
<BODY>
<form>
Give the name of HTML file to open in Frame2
<input type="text" name="f1text">
<input type="button" value="Open File in Frame 2" onClick="writeFrame2()">
<form>
</BODY>
</HTML>
If Frames have no name, they can still be referred, like we referred forms. You
guessed it right, first frame is frames[0], second frame is frames[1], and so on.
So we can refer to first frame as parent.frames[0].

Using Frames to Store
Pseudo-Persistent Data
       When you are working with frames, it is sometimes useful to be able to
store information in JavaScript variables in such a way that the variable is
available to both the frames.
<frameset cols=”50%,50%”>
       <frame name=”frame1” src=”frame1.html”>
       <frame name=”frame2” src=””>
</framesest>

In the above code, there are three documents.
1. Frame set document.
2. document present in frame1.
3. document present in frame2.

Actually frameset document, contains within itself two more documents,
(document of frame1) and (document in frame2 ).

If you create any variable in document of frame1, it will not be accessible to
document of frame 2. Simmilarly, if you create a variable in document of frame 2,
it will not be accessible to document of frame1. So, you can create a variable in
frameset document, which will be accessible to both frame 1 and frame 2.

So, now create a variable in frameset.html,
Below is the code for frameset.html

<script language="JavaScript">
       var pVariable="This is a persistent value"
</script>
<frameset cols=”50%,50%”>
       <frame name=”frame1” src=”frame1.html”>
       <frame name=”frame2” src=”frame2.html”>
</framesest>

Below is the code for frame1.html

<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>
<BODY>
This is frame 1 <br>
<script language="JavaScript">
document.write("The value of persistent variable is "+parent.pVariable);
</script>
</BODY>
</HTML>

Below is the code for frame2.html
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>
<BODY>
This is frame 2 <br>
<script language="JavaScript">
document.write("The value of persistent variable is "+parent.pVariable);
</script>
</BODY>
</HTML>

More Related Content

What's hot (15)

Visual Studio.Net - Sql Server
Visual Studio.Net - Sql ServerVisual Studio.Net - Sql Server
Visual Studio.Net - Sql Server
Darwin Durand
 
Aspnet mvc tutorial_9_cs
Aspnet mvc tutorial_9_csAspnet mvc tutorial_9_cs
Aspnet mvc tutorial_9_cs
Murali G
 
Ajax chap 5
Ajax chap 5Ajax chap 5
Ajax chap 5
Mukesh Tekwani
 
Ajax chap 4
Ajax chap 4Ajax chap 4
Ajax chap 4
Mukesh Tekwani
 
Java script programms
Java script programmsJava script programms
Java script programms
Mukund Gandrakota
 
Aplikasi rawat-inap-vbnet
Aplikasi rawat-inap-vbnetAplikasi rawat-inap-vbnet
Aplikasi rawat-inap-vbnet
Diaz Alfahrezy
 
Ajax chap 3
Ajax chap 3Ajax chap 3
Ajax chap 3
Mukesh Tekwani
 
Ajax chap 2.-part 1
Ajax chap 2.-part 1Ajax chap 2.-part 1
Ajax chap 2.-part 1
Mukesh Tekwani
 
phptut2
phptut2phptut2
phptut2
tutorialsruby
 
How to check Google Analytics tags
How to check Google Analytics tagsHow to check Google Analytics tags
How to check Google Analytics tags
Yuhui
 
Android Testing
Android TestingAndroid Testing
Android Testing
Evan Lin
 
The Ring programming language version 1.5.3 book - Part 43 of 184
The Ring programming language version 1.5.3 book - Part 43 of 184The Ring programming language version 1.5.3 book - Part 43 of 184
The Ring programming language version 1.5.3 book - Part 43 of 184
Mahmoud Samir Fayed
 
05 html-forms
05 html-forms05 html-forms
05 html-forms
Palakshya
 
Advance JFACE
Advance JFACEAdvance JFACE
Advance JFACE
Rahul Shukla
 
14922 java script built (1)
14922 java script built (1)14922 java script built (1)
14922 java script built (1)
dineshrana201992
 
Visual Studio.Net - Sql Server
Visual Studio.Net - Sql ServerVisual Studio.Net - Sql Server
Visual Studio.Net - Sql Server
Darwin Durand
 
Aspnet mvc tutorial_9_cs
Aspnet mvc tutorial_9_csAspnet mvc tutorial_9_cs
Aspnet mvc tutorial_9_cs
Murali G
 
Aplikasi rawat-inap-vbnet
Aplikasi rawat-inap-vbnetAplikasi rawat-inap-vbnet
Aplikasi rawat-inap-vbnet
Diaz Alfahrezy
 
How to check Google Analytics tags
How to check Google Analytics tagsHow to check Google Analytics tags
How to check Google Analytics tags
Yuhui
 
Android Testing
Android TestingAndroid Testing
Android Testing
Evan Lin
 
The Ring programming language version 1.5.3 book - Part 43 of 184
The Ring programming language version 1.5.3 book - Part 43 of 184The Ring programming language version 1.5.3 book - Part 43 of 184
The Ring programming language version 1.5.3 book - Part 43 of 184
Mahmoud Samir Fayed
 
05 html-forms
05 html-forms05 html-forms
05 html-forms
Palakshya
 
14922 java script built (1)
14922 java script built (1)14922 java script built (1)
14922 java script built (1)
dineshrana201992
 

Viewers also liked (16)

Lecture1 introductiontonetwork
Lecture1 introductiontonetworkLecture1 introductiontonetwork
Lecture1 introductiontonetwork
H K
 
Java script objects 2
Java script objects 2Java script objects 2
Java script objects 2
H K
 
Assignment4
Assignment4Assignment4
Assignment4
H K
 
Week5
Week5Week5
Week5
H K
 
Lecture4 isoosi
Lecture4 isoosiLecture4 isoosi
Lecture4 isoosi
H K
 
Set
SetSet
Set
H K
 
Lecture2 networkclassification
Lecture2 networkclassificationLecture2 networkclassification
Lecture2 networkclassification
H K
 
Assignment sw
Assignment swAssignment sw
Assignment sw
H K
 
Html basics 6 image
Html basics 6 imageHtml basics 6 image
Html basics 6 image
H K
 
Solution2
Solution2Solution2
Solution2
H K
 
Html basics 3 font align
Html basics 3 font alignHtml basics 3 font align
Html basics 3 font align
H K
 
Html basics 10 form
Html basics 10 formHtml basics 10 form
Html basics 10 form
H K
 
Induction
InductionInduction
Induction
H K
 
Html basics 1
Html basics 1Html basics 1
Html basics 1
H K
 
Html basics 7 table
Html basics 7 tableHtml basics 7 table
Html basics 7 table
H K
 
Week7
Week7Week7
Week7
H K
 
Lecture1 introductiontonetwork
Lecture1 introductiontonetworkLecture1 introductiontonetwork
Lecture1 introductiontonetwork
H K
 
Java script objects 2
Java script objects 2Java script objects 2
Java script objects 2
H K
 
Assignment4
Assignment4Assignment4
Assignment4
H K
 
Week5
Week5Week5
Week5
H K
 
Lecture4 isoosi
Lecture4 isoosiLecture4 isoosi
Lecture4 isoosi
H K
 
Set
SetSet
Set
H K
 
Lecture2 networkclassification
Lecture2 networkclassificationLecture2 networkclassification
Lecture2 networkclassification
H K
 
Assignment sw
Assignment swAssignment sw
Assignment sw
H K
 
Html basics 6 image
Html basics 6 imageHtml basics 6 image
Html basics 6 image
H K
 
Solution2
Solution2Solution2
Solution2
H K
 
Html basics 3 font align
Html basics 3 font alignHtml basics 3 font align
Html basics 3 font align
H K
 
Html basics 10 form
Html basics 10 formHtml basics 10 form
Html basics 10 form
H K
 
Induction
InductionInduction
Induction
H K
 
Html basics 1
Html basics 1Html basics 1
Html basics 1
H K
 
Html basics 7 table
Html basics 7 tableHtml basics 7 table
Html basics 7 table
H K
 
Week7
Week7Week7
Week7
H K
 
Ad

Similar to Java script frame window (20)

Internet Based Programming -3-JAVASCRIPT
Internet Based Programming -3-JAVASCRIPTInternet Based Programming -3-JAVASCRIPT
Internet Based Programming -3-JAVASCRIPT
stevecom2010
 
wp-UNIT_III.pptx
wp-UNIT_III.pptxwp-UNIT_III.pptx
wp-UNIT_III.pptx
GANDHAMKUMAR2
 
13488117.ppt
13488117.ppt13488117.ppt
13488117.ppt
SunilChaluvaiah
 
13488117.ppt
13488117.ppt13488117.ppt
13488117.ppt
SunilChaluvaiah
 
lect4
lect4lect4
lect4
tutorialsruby
 
lect4
lect4lect4
lect4
tutorialsruby
 
Java script Advance
Java script   AdvanceJava script   Advance
Java script Advance
Jaya Kumari
 
JavaScript lesson 1.pptx
JavaScript lesson 1.pptxJavaScript lesson 1.pptx
JavaScript lesson 1.pptx
MuqaddarNiazi1
 
Java script browser objects 1
Java script browser objects 1Java script browser objects 1
Java script browser objects 1
H K
 
FYBSC IT Web Programming Unit III Javascript
FYBSC IT Web Programming Unit III JavascriptFYBSC IT Web Programming Unit III Javascript
FYBSC IT Web Programming Unit III Javascript
Arti Parab Academics
 
Javascript
Javascript Javascript
Javascript
poojanov04
 
Unit5_Web_Updvvgxsvjbffcvvgbjifszated.pptx
Unit5_Web_Updvvgxsvjbffcvvgbjifszated.pptxUnit5_Web_Updvvgxsvjbffcvvgbjifszated.pptx
Unit5_Web_Updvvgxsvjbffcvvgbjifszated.pptx
1si23bt001
 
Java script advanced frame
Java script advanced frameJava script advanced frame
Java script advanced frame
H K
 
Introduction to java script, how to include java in HTML
Introduction to java script, how to include java in HTMLIntroduction to java script, how to include java in HTML
Introduction to java script, how to include java in HTML
backiyalakshmi14
 
The Ring programming language version 1.5.3 book - Part 81 of 184
The Ring programming language version 1.5.3 book - Part 81 of 184The Ring programming language version 1.5.3 book - Part 81 of 184
The Ring programming language version 1.5.3 book - Part 81 of 184
Mahmoud Samir Fayed
 
Java Script
Java ScriptJava Script
Java Script
Kalidass Balasubramaniam
 
eXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction TrainingeXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction Training
Hoat Le
 
Javascript1
Javascript1Javascript1
Javascript1
anas Mohtaseb
 
Jquery
JqueryJquery
Jquery
Gulbir Chaudhary
 
Devoxx 2014-webComponents
Devoxx 2014-webComponentsDevoxx 2014-webComponents
Devoxx 2014-webComponents
Cyril Balit
 
Internet Based Programming -3-JAVASCRIPT
Internet Based Programming -3-JAVASCRIPTInternet Based Programming -3-JAVASCRIPT
Internet Based Programming -3-JAVASCRIPT
stevecom2010
 
Java script Advance
Java script   AdvanceJava script   Advance
Java script Advance
Jaya Kumari
 
JavaScript lesson 1.pptx
JavaScript lesson 1.pptxJavaScript lesson 1.pptx
JavaScript lesson 1.pptx
MuqaddarNiazi1
 
Java script browser objects 1
Java script browser objects 1Java script browser objects 1
Java script browser objects 1
H K
 
FYBSC IT Web Programming Unit III Javascript
FYBSC IT Web Programming Unit III JavascriptFYBSC IT Web Programming Unit III Javascript
FYBSC IT Web Programming Unit III Javascript
Arti Parab Academics
 
Unit5_Web_Updvvgxsvjbffcvvgbjifszated.pptx
Unit5_Web_Updvvgxsvjbffcvvgbjifszated.pptxUnit5_Web_Updvvgxsvjbffcvvgbjifszated.pptx
Unit5_Web_Updvvgxsvjbffcvvgbjifszated.pptx
1si23bt001
 
Java script advanced frame
Java script advanced frameJava script advanced frame
Java script advanced frame
H K
 
Introduction to java script, how to include java in HTML
Introduction to java script, how to include java in HTMLIntroduction to java script, how to include java in HTML
Introduction to java script, how to include java in HTML
backiyalakshmi14
 
The Ring programming language version 1.5.3 book - Part 81 of 184
The Ring programming language version 1.5.3 book - Part 81 of 184The Ring programming language version 1.5.3 book - Part 81 of 184
The Ring programming language version 1.5.3 book - Part 81 of 184
Mahmoud Samir Fayed
 
eXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction TrainingeXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction Training
Hoat Le
 
Devoxx 2014-webComponents
Devoxx 2014-webComponentsDevoxx 2014-webComponents
Devoxx 2014-webComponents
Cyril Balit
 
Ad

More from H K (20)

Assignment4
Assignment4Assignment4
Assignment4
H K
 
Assignment3
Assignment3Assignment3
Assignment3
H K
 
Solution3
Solution3Solution3
Solution3
H K
 
Mid-
Mid-Mid-
Mid-
H K
 
Assignment4
Assignment4Assignment4
Assignment4
H K
 
Dm assignment3
Dm assignment3Dm assignment3
Dm assignment3
H K
 
Proof
ProofProof
Proof
H K
 
Resolution
ResolutionResolution
Resolution
H K
 
Assignment description
Assignment descriptionAssignment description
Assignment description
H K
 
Dm assignment2
Dm assignment2Dm assignment2
Dm assignment2
H K
 
Dm assignment1
Dm assignment1Dm assignment1
Dm assignment1
H K
 
Logic
LogicLogic
Logic
H K
 
Introduction
IntroductionIntroduction
Introduction
H K
 
Assignment 2 sol
Assignment 2 solAssignment 2 sol
Assignment 2 sol
H K
 
Assignment sw solution
Assignment sw solutionAssignment sw solution
Assignment sw solution
H K
 
Violinphoenix
ViolinphoenixViolinphoenix
Violinphoenix
H K
 
Ie project
Ie projectIe project
Ie project
H K
 
Assignment cn subnetting
Assignment cn subnettingAssignment cn subnetting
Assignment cn subnetting
H K
 
Assignment uplaodfile
Assignment uplaodfileAssignment uplaodfile
Assignment uplaodfile
H K
 
Assignment sw
Assignment swAssignment sw
Assignment sw
H K
 
Assignment4
Assignment4Assignment4
Assignment4
H K
 
Assignment3
Assignment3Assignment3
Assignment3
H K
 
Solution3
Solution3Solution3
Solution3
H K
 
Mid-
Mid-Mid-
Mid-
H K
 
Assignment4
Assignment4Assignment4
Assignment4
H K
 
Dm assignment3
Dm assignment3Dm assignment3
Dm assignment3
H K
 
Proof
ProofProof
Proof
H K
 
Resolution
ResolutionResolution
Resolution
H K
 
Assignment description
Assignment descriptionAssignment description
Assignment description
H K
 
Dm assignment2
Dm assignment2Dm assignment2
Dm assignment2
H K
 
Dm assignment1
Dm assignment1Dm assignment1
Dm assignment1
H K
 
Logic
LogicLogic
Logic
H K
 
Introduction
IntroductionIntroduction
Introduction
H K
 
Assignment 2 sol
Assignment 2 solAssignment 2 sol
Assignment 2 sol
H K
 
Assignment sw solution
Assignment sw solutionAssignment sw solution
Assignment sw solution
H K
 
Violinphoenix
ViolinphoenixViolinphoenix
Violinphoenix
H K
 
Ie project
Ie projectIe project
Ie project
H K
 
Assignment cn subnetting
Assignment cn subnettingAssignment cn subnetting
Assignment cn subnetting
H K
 
Assignment uplaodfile
Assignment uplaodfileAssignment uplaodfile
Assignment uplaodfile
H K
 
Assignment sw
Assignment swAssignment sw
Assignment sw
H K
 

Recently uploaded (20)

Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.
jmansha170
 
Exploring Ocean Floor Features for Middle School
Exploring Ocean Floor Features for Middle SchoolExploring Ocean Floor Features for Middle School
Exploring Ocean Floor Features for Middle School
Marie
 
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptxPests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Arshad Shaikh
 
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti MpdBasic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Restu Bias Primandhika
 
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptxAnalysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Shrutidhara2
 
IDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptxIDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptx
ArneeAgligar
 
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
EduSkills OECD
 
Parenting Teens: Supporting Trust, resilience and independence
Parenting Teens: Supporting Trust, resilience and independenceParenting Teens: Supporting Trust, resilience and independence
Parenting Teens: Supporting Trust, resilience and independence
Pooky Knightsmith
 
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Celine George
 
BUSINESS QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 9 SEPTEMBER 2024
BUSINESS QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 9 SEPTEMBER 2024BUSINESS QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 9 SEPTEMBER 2024
BUSINESS QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 9 SEPTEMBER 2024
Quiz Club of PSG College of Arts & Science
 
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
GeorgeDiamandis11
 
Adam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational PsychologyAdam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational Psychology
Prachi Shah
 
How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18
Celine George
 
Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...
Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...
Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...
National Information Standards Organization (NISO)
 
LDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad UpdatesLDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad Updates
LDM & Mia eStudios
 
Ray Dalio How Countries go Broke the Big Cycle
Ray Dalio How Countries go Broke the Big CycleRay Dalio How Countries go Broke the Big Cycle
Ray Dalio How Countries go Broke the Big Cycle
Dadang Solihin
 
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptxDiptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Arshad Shaikh
 
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition OecdEnergy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
razelitouali
 
Strengthened Senior High School - Landas Tool Kit.pptx
Strengthened Senior High School - Landas Tool Kit.pptxStrengthened Senior High School - Landas Tool Kit.pptx
Strengthened Senior High School - Landas Tool Kit.pptx
SteffMusniQuiballo
 
Allomorps and word formation.pptx - Google Slides.pdf
Allomorps and word formation.pptx - Google Slides.pdfAllomorps and word formation.pptx - Google Slides.pdf
Allomorps and word formation.pptx - Google Slides.pdf
Abha Pandey
 
Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.
jmansha170
 
Exploring Ocean Floor Features for Middle School
Exploring Ocean Floor Features for Middle SchoolExploring Ocean Floor Features for Middle School
Exploring Ocean Floor Features for Middle School
Marie
 
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptxPests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Arshad Shaikh
 
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti MpdBasic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Restu Bias Primandhika
 
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptxAnalysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Shrutidhara2
 
IDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptxIDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptx
ArneeAgligar
 
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
EduSkills OECD
 
Parenting Teens: Supporting Trust, resilience and independence
Parenting Teens: Supporting Trust, resilience and independenceParenting Teens: Supporting Trust, resilience and independence
Parenting Teens: Supporting Trust, resilience and independence
Pooky Knightsmith
 
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Celine George
 
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
GeorgeDiamandis11
 
Adam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational PsychologyAdam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational Psychology
Prachi Shah
 
How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18
Celine George
 
LDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad UpdatesLDMMIA Reiki Yoga Next Week Grad Updates
LDMMIA Reiki Yoga Next Week Grad Updates
LDM & Mia eStudios
 
Ray Dalio How Countries go Broke the Big Cycle
Ray Dalio How Countries go Broke the Big CycleRay Dalio How Countries go Broke the Big Cycle
Ray Dalio How Countries go Broke the Big Cycle
Dadang Solihin
 
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptxDiptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Arshad Shaikh
 
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition OecdEnergy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
razelitouali
 
Strengthened Senior High School - Landas Tool Kit.pptx
Strengthened Senior High School - Landas Tool Kit.pptxStrengthened Senior High School - Landas Tool Kit.pptx
Strengthened Senior High School - Landas Tool Kit.pptx
SteffMusniQuiballo
 
Allomorps and word formation.pptx - Google Slides.pdf
Allomorps and word formation.pptx - Google Slides.pdfAllomorps and word formation.pptx - Google Slides.pdf
Allomorps and word formation.pptx - Google Slides.pdf
Abha Pandey
 

Java script frame window

  • 1. Lecture 18 In this lecture, we will learn -> Validating Radio Button Validating Radio Button Selections A radio button, provide a set of options, out of which only one can be selected. Infact, there are lot of simillarities between radio button and check box. Except one dissimillarity, which is, check box provide a lot of options to be selected whereas you can only select one option with radio button. To know which option is selected, the following statement can be used document.name of the form.name of the button[i].checked, The above statement returns true if the button is selected otherwise false. The value of 'i' ranges from (0 to number_of_radio_buttons - 1 ). Let us take an example. <HTML> <HEAD> <TITLE> New Document </TITLE> <script language="JavaScript"> function validate() { number_of_radio_buttons=document.myForm.hobby.length; for (i=0;i<=number_of_radio_buttons-1;i++) { if (document.myForm.hobby[i].checked) { flag=1; you_selected=document.myForm.hobby[i].value; window.alert(you_selected); return true; } else flag=0; } if (flag==0) { window.alert("Error! You should select one of the options"); return false; } } </script>
  • 2. </HEAD> <BODY> My hobbies are <form method="get" action="display.asp" name="myForm" onSubmit="return validate()"> <input type="radio" name="hobby" value="soccer"> Soccer <br> <input type="radio" name="hobby" value="read"> Reading <br> <input type="radio" name="hobby" value="music"> Listening Music <br> <input type="radio" name="hobby" value="travel"> Travelling <br> <input type="submit" value="Validate"> </form> </BODY> </HTML> Let us summarize, what we have learned by the above program 1. To know the number of radio buttons: document.name of form.name of radio button.length 2. To know index of radio button selected: document.name of form.name of radio button[i].selected 3. To know the value of radio button selected: document.name of form.name of radio button[i].value Using the Window Object We will discuss more about the Window object. We have been already using the Window object before. Some of the features of Window object are 1. Creating Alert Dialog Boxes: window.alert() 2. Creating Confirmation Dialog Boxes: window.confirm() 3. Creating Dialog Boxes to get: window.prompt() information from the user. 4. Opening Pages in new window: window.open() 5. Determining window size 6. Controlling scrolling of the document displayed in window 7. Scheduling the execution of function: window.setTimeout() So, we have done all this before. This is all we have to learn about window object.
  • 3. Open a Full Screen window The following is the code to open a full screen window <HTML> <HEAD> <TITLE> New Document </TITLE> <script language="JavaScript"> function showWindow() { window.open("","myNewWindow","fullScreen=yes"); } </script> </HEAD> <BODY> <a href="a.html" onMouseOver="showWindow()" >Click1</a> </BODY> </HTML> Handling the Parent-Child Relationship of Windows When the window.open() method is used to open a new window from JavaScript, a relationship exist between the original window and new window so that it is possible to refer to both the windows from within JavaScript. Well, to refer to the child window, simply do this var newWindow=window.open(“URL”,window name); Now you can refer to the new window, by newWindow. Let us take an example <HTML> <HEAD> <TITLE> New Document </TITLE> <script language="JavaScript"> function showWindow() { myNewWindow=window.open("","myNewWindow"); } function closeWindow()
  • 4. { myNewWindow.close(); } function closeThisWindow() { window.close(); } </script> </HEAD> <BODY> <a href="" onMouseOver="showWindow()" >Take the Mouse here to open a New window</a> <br> <a href="" onMouseOver='closeWindow()' >Take the Mouse here to close the Opened Window</a><br> <a href="" onMouseOver="closeThisWindow()">Take the Mouse here to close this Window</a> </BODY> </HTML> Let us take another example, where you will open a new window. The new window have the option for closing the parent window. <HTML> <HEAD> <TITLE> New Document </TITLE> <script language="JavaScript"> function showWindow() { myNewWindow=window.open("a.html","myNewWindow"); } function closeWindow() { myNewWindow.close(); } function closeThisWindow() { window.close(); } </script> </HEAD> <BODY> <a href="" onMouseOver="showWindow()" >Take the Mouse here to open
  • 5. a New window</a> <br> </BODY> </HTML> Here is the code for a.html <HTML> <HEAD> <TITLE> New Document </TITLE> <script language="JavaScript"> function closeOriginalWindow() { window.opener.close(); } </script> </HEAD> <BODY> <a href="" onMouseOver="closeOriginalWindow()">close the original Window</a> </BODY> </HTML> Writing into New Window Below is the code, to write into new Window <HTML> <HEAD> <TITLE> New Document </TITLE> <script language="JavaScript"> function showWindow() { myNewWindow=window.open("","myNewWindow","width=200, height=200, left=20, top=50"); myNewWindow.document.open(); myNewWindow.document.write("Take your mouse here to open new window"); myNewWindow.document.close(); } function closeWindow() { myNewWindow.close();
  • 6. } function closeThisWindow() { window.close(); } </script> </HEAD> <BODY> <a href="" onMouseOver="showWindow()" >Take the Mouse here to open a New window</a> <br> </BODY> </HTML> Referring Frames In JavaScript If there are two frames on one page, name of left frame is frame1, and name of right frame is frame2, Then frame1 can be referred in JavaScript as parent.frame1 and similarly, frame2 can be referred as paraent.frame2. Let us take an example, first make frameset.html, which contains two frames, frame1 and frame2. <frameset cols=”50%,50%”> <frame name=”frame1” src=”frame1.html”> <frame name=”frame2” src=”frame2.html”> </framesest> Here is the code for frame1.html <HTML> <HEAD> <TITLE> New Document </TITLE> <script language="JavaScript"> function writeFrame2() { parent.frame2.document.open(); parent.frame2.document.write(document.forms[0].f1text.value); parent.frame2.document.close(); } </script> </HEAD> <BODY>
  • 7. <form> <input type="text" name="f1text"> <input type="button" value="Write this to Frame 2" onClick="writeFrame2()"> <form> </BODY> </HTML> To understand more about Frame object, Let me compare Frame object with Window object. In the previous topic, we saw that, window can use the document object, for ex. window.document.open(), Simmilarly, we can say frame.document.open(), and then can write into the frame, as you can see in the abov example. Infact we can use all the functions provided by the document object. So, the moral of the story is "Frame object contain a document object". Let us take another simple example This is the code for frameset.html <frameset cols=”50%,50%”> <frame name=”frame1” src=”frame1.html”> <frame name=”frame2” src=””> </framesest> Notice that, source for frame2 doesnot exist Below is the code for frame1.html <HTML> <HEAD> <TITLE> New Document </TITLE> <script language="JavaScript"> function writeFrame2() { parent.frame2.document.location=document.forms[0].f1text.value; } </script> </HEAD> <BODY> <form> Give the name of HTML file to open in Frame2 <input type="text" name="f1text"> <input type="button" value="Open File in Frame 2" onClick="writeFrame2()"> <form> </BODY> </HTML>
  • 8. If Frames have no name, they can still be referred, like we referred forms. You guessed it right, first frame is frames[0], second frame is frames[1], and so on. So we can refer to first frame as parent.frames[0]. Using Frames to Store Pseudo-Persistent Data When you are working with frames, it is sometimes useful to be able to store information in JavaScript variables in such a way that the variable is available to both the frames. <frameset cols=”50%,50%”> <frame name=”frame1” src=”frame1.html”> <frame name=”frame2” src=””> </framesest> In the above code, there are three documents. 1. Frame set document. 2. document present in frame1. 3. document present in frame2. Actually frameset document, contains within itself two more documents, (document of frame1) and (document in frame2 ). If you create any variable in document of frame1, it will not be accessible to document of frame 2. Simmilarly, if you create a variable in document of frame 2, it will not be accessible to document of frame1. So, you can create a variable in frameset document, which will be accessible to both frame 1 and frame 2. So, now create a variable in frameset.html, Below is the code for frameset.html <script language="JavaScript"> var pVariable="This is a persistent value" </script> <frameset cols=”50%,50%”> <frame name=”frame1” src=”frame1.html”> <frame name=”frame2” src=”frame2.html”> </framesest> Below is the code for frame1.html <HTML> <HEAD> <TITLE> New Document </TITLE> </HEAD>
  • 9. <BODY> This is frame 1 <br> <script language="JavaScript"> document.write("The value of persistent variable is "+parent.pVariable); </script> </BODY> </HTML> Below is the code for frame2.html <HTML> <HEAD> <TITLE> New Document </TITLE> </HEAD> <BODY> This is frame 2 <br> <script language="JavaScript"> document.write("The value of persistent variable is "+parent.pVariable); </script> </BODY> </HTML>