Download as pdf or txt
Download as pdf or txt
You are on page 1of 56

яskp u

 
• яskp Syntax
• яskp Enable
• яskp Location
• яskp External
• яskp Operator
• яskp Variable
• яskp Function
• яskp Event
• яskp Statement
• If Statement
• Else If Statement
• While Loop
• For Loop
• Comments
• яskp Array
• яskp Alert
• яskp Confirm
• яskp Prompt
• яskp Print
• яskp Redirect
• яskp Popup
• яskp Date
• яskp 
• яskp s
• яskp s 
• яskp s sp

• яskp s 


• яskp  p
• яskp indexOf
• яskp getElementById
• яskp inner

яskp u
  |  ( Javascr i pt Tut or i al i n Bangl a)
  : 
    

e! e !"# ! я$ " p &'  &।ei я$ " ! яstp।яskp + e kin i. skp $# я & buя skp।
kin i. skp $# я e a1 + c 3 o 5& buя  & " buя ei skp$#   run/execute  &।kin i. e
&6 7" +   i.,  i. $# я $#  . o &   e 8  execute/run +5।яstp e p8! #&8
+ e 8  я
 i
e p"  9! :; e 35।

яstp e + 3 !  я$#  e 35।


• 
• Mouse Trailers ( site buя e 5 u e :; e! '!)
• <6.u! !#
• Alert  я
• 666 ui n
• HTML Form  .'!
• si. '
•  n &
webcoachbd.com e u
 5 $# 6@ 6! & 5 яskp (Javascript) ' " 6 &!।

p5 6A&:n ei u
  '# #    $ 6!  a&'i eiee m n  я! " + &।

яskp 
$  %
& ' ( Javascr i pt Synt ax Tut or i al i n Bangl a)
  : 
    

"! $# #t6#! 86 F 3 6!  яskp   k t p я! ।

1. script
$ &&+  buя  &I " + & 3 6! яskp &&+  F!।

2. F# яskp .   " + & ।


3. Test the script

+,- p/ яskp 01


  p1 86 + c <script>
$ &&+ 8  buя  &I " + & 3   яskp &&+  F। script
type + & "text/JavaScript" 
 " + &। 6!  ee e k t   F! type + &   "text/css" 

 F।
01.<html>
02.<body>
03.<script type="text/JavaScript">
04.<!--
05.document.write("Hello World!")
06.//-->
07.</script>
08.</body>
09.</html>
p'!:
Hello world!

document.write:
  script e '9 86 + c '! e &&+ 3 ! document.write ।যার 8  text, HTML a1& J i
  3 ।   ei '! e e
 &" text string &&+  F 3 "Hello World!" !  6 "। e buя e
p'" + &।

SYNTAX $ 6h:
6h:
u6 яstp . k   " 6 &! 3 "document.write(Hello World!)" ei statement e ' 9 !
  ! !i।  ! p " statement e '9 !  '  " яstp e   ! e p я! !i।
" & 6! 3 aj pg + 1 ! " &  k t &&+  " 6 !। " &   ! &&+   я # 7 3!   e
i ! # statement ( # document.write statements )  ।

яskp 9k   ( JavaScr i pt Enabl e Tut or i al i n Bangl a)


  : 
    

e a8 6!   &  & яstp in !


ek p  ,  k, e& a 6  "  (active)  " + ।

яskp 0 i?
-
i?
- ek
p  -
ek
p  - e 96   ,d&:
  ,d&:
Internet Explorer 6/7 e 6! security setting e $ check  " 6 ! 3 6! яstp   F
!। !  яstp    u6   + ।
1 p1  Tools menu " Click  " + &
2 " 6 menu + " Internet Options !&!  " + &
3 Internet Options e Security tab e Click  " + &
4 " 6 Custom Level &
! Click  security settings e p &'  " + &
5 Scroll  Scripting section e 3 " + &
6 script    я! Enable &
! Select  " + &
7 pk  mn  " OK &
! Click  " + &
8   я! Yes &
! Click  " + &

яskp 0 E  Ek-
E  Ek- e 96   ,d&:
  ,d&:
Firefox 2 e 6! Options e Content setting e $ check  " 6 ! 3 6! яstp   F
!। !  яstp    u6   + ।
1 p1  Tools menu " Click  " + &
2 " 6 menu + " Options !&!  " + &
3 Options e Content tab e Click  " + &
4 !Y"  #! 3 Enable JavaScript check box e     F !
5 pk  mn  " OK &
! Click  " + &

яskp 0 a
,  – 0& 96   ,d&:
  ,d&:
Opera " 6! Preferences e Content setting e $ check  " 6 ! 3 6! яstp   F
!। !  яstp    u6   + ।
1 p1  Tools menu " Click  " + &
2 " 6 menu + " Preferences !&!  " + &
3 Preferences e Advanced tab e Click  " + &
4 & 6 '  s item + " Content !&!  " + &
5 !Y"  #! 3 Enable JavaScript check box e     F !
6 pk  mn  " OK &
! Click  " + &

яskp 01 0/ /


$ ( Wher e To pl ace Javascr i pt Code)
  : 
    

"! 8 ! a&s! F 3 ! яskp .   3 ।


1 head
$ e "
2 body
$ e  8
3 &+\s (external) file + &
head or body e a&s! 6Fn   #& 8 !। 3 6! ! яskp  F# event (3! 3! ! &&+  7 !
s ! k  &, event m n  !   + F) e u6 !   &!  k t 6! яskp  head
$ e  " 6 !।
& 3 6! яskp  !   " ! 3! 6я  . + & (6#&& " a8 "Hello World!" u+ ! "), k t
6! яskp  body
$ e  8  " 6 !।

&+\s (External) яskp i e& "  &&+ 6 &" a8  !   + F ।

HEAD SCRIPT e uP' -:


uP' -:
3 +"#    F 3 e p Script 3 body tag e  8   3 ।   F# Script   & 3 8  F# event
" + & ।যেমন &&+  7 3! &
! k  & "! alert box  &।
01.<html>
02.<head>
03.<script type="text/JavaScript">
04.<!--
05.function popup() {
06.alert("Hello World")
07.}
08.//-->
09.</script>
10.</head>
11.<body>
12.<input type="button" onclick="popup()" value="popup">
13.</body>
14.</html>
p'!:
  e
 '! " 7  F 3 ! 666 e& e
  eiee .k n e head
$ e  F ।e!   3"& i
&
! k  & ""& i "Hello World!" !  alert box  &। 6 &" a8 $# " '! e& event m n &s "
 !   + F ।

$':
$':s $ ek-R яskp Ei ( Ext er nal JavaScr i pt Fi l e Tut or i al i n
Bangl a)
  : 
    

eiee .k n e head e& body


$ e яskp e a&s! 6#&& " a8  !   + F । e!  
 !  & ": "7 a&s! m  3 + c external яskp file ।

$':
$':s ( EXTERNAL) яskp Ei i
,R   - :
- :
external яskp file Import   I  #k я। p1" 3 i   Import  &! 
 &8 e& '#8# t яskp
file + " + &।d"7 " i extension  a&'i ".js" + " + & ।পরিশেষে 6!  a&'i file e a&s! я! " + &।
8  3 "myjs.js" !    e file  F 3 e i ! Hello World !  alert function  8 !
 F। o 8  3 HTML file e& яskp file ei directory "  F।
myjs.js !  яskp file :
1.function popup() {
2.alert("Hello World")
3.}
01.<html>
02.<head>
03.<script src="/myjs.js">
04.</script>
05.</head>
06.<body>
07.<input type="button" onclick="popup()" value="Click Me!">
08.</body>
09.</html>
p'!:
F# Tips:
1 6! 3 ei Script &n 6 я &&+  " ! "+ external яskp file &&+  " 6 !।e  ei .
p " 6 я я!   p я! !i।
2 u 8 ! Script e я! external яskp file &&+   3 3! e!
i6 3 head tag (functions) e 
+  
i6 3 body tag e  + ।
3 6!  !Y"  " + & 3 external яskp file e <script> tag an#k + & !।  ! '#8# t HTML
comment e& яskp code Fa  F# 1 & !।

яskp a,
 u
  ( JavaScr i pt Oper at or Tut or i al i n
Bangl a)
  : 
    

a!! pg $# я e a6


e  1 яskp a6
e   F। a6
+ c e! e symbol(p"7)
3 ! $!"7 я  " &&h" + । &' $ k t я$#  + c 6$!"7 ( arithmetic) 3! 3$, & $ i" " &
& k t ! ।

яskp e ,V-&W a,


 e & :
& :
Operator 1 u+ !

+ 3$ 2+44
- & $ 6-22
* $#! 7*44
/ $ 15/3
15 3
% .#  43%
43 10

яskp a,
 e 0
$ 9' uP' -:
uP' -:
!  e
 8 ! u+ !   +  3 !   6$!"7 3 mn + F ।
01.<body>
02.<script type="text/JavaScript">
03.<!--
04.var two = 2
05.var ten = 10
06.var linebreak = "<br />"
07.
08.document.write("two plus ten = ")
09.var result = two + ten
10.document.write(result)
11.document.write(linebreak)
12.
13.
14.document.write("ten * ten = ")
15.result = ten * ten
16.document.write(result)
17.document.write(linebreak)
18.
19.document.write("ten / two = ")
20.result = ten / two
21.document.write(result)
22.//-->
23.</script>
24.</body>
p'!:
two plus ten = 12
ten * ten = 100
ten / two = 5

COMPARI SON a,


 :
a,
 :
variables & values e  8 m !d  " Comparison a6
&&h" + । e
 equal h 3  # 

 double equal h (==) #  #  8 "# !  Comparison a6
3conditional
3 statement e
" 1 !d  । conditional statement m n 6 &" a8  !   + F ।
" &&h" + e& ",

Operator 1 u+ !  

== Equal To x==y 1

!= Not Equal To x!=y "

< Less Than x<y "

> Greater Than x>y 1

<= Less Than or Equal To x<=y "

>= Greater Than or Equal To x>=y 1


яskp 0
$ u
  ( JavaScr i pt Var i abl e Tut or i al i n
Bangl a)
  : 
    

 & + e
 p"7 (symbolic) ! 3 6! ! ;     #  u6s6!  ।  & e
e u d' + c 6!
"1  я  3 " 6! 6 &" " " &&+  " 6 !।  & ! 
!  3   e
 &я & $  1 "# ! 
"+ ei & $ &я  .
 (data) 1
 1 "# !   3 । Variable ! ( name) d  .
 a ! 1  3 " 6!
+ я e
  move  " 6 !।
  " 6 !।
 & e u+ !:
u+ !
p1&  & &&+ k t  & !  6# & "var"   я # 7 ! " &  programming practice e я!
p1&  & !  6# & "var"   u"।!  u+ ! 8  &9  6 s   + ।
01.<body>
02.<script type="text/JavaScript">
03.<!--
04.var linebreak = "<br />"
05.var my_var = "Hello World!"
06.
07.document.write(my_var)
08.document.write(linebreak)
09.
10.my_var = "I am learning JavaScript!"
11.document.write(my_var)
12.document.write(linebreak)
13.
14.my_var = "Script is Finishing up..."
15.document.write(my_var)
16.//-->
17.</script>
18.</body>
p'!:
Hello World!
I am learning JavaScript!
Script is Finishing up...
u6 u+ !   #  & " 7  F 3 e i! b  я! HTML  8 F a6  + c .i!  &
3 u6 script e  8 "! n 8 !  # F।
 & e  # ! ;  " ! h (=) &&+  " + &। 3 ! & 6 ' 1 &  & e& .! 6 ' 1 &  &
e  #। 3! my_var = "Hello World!" e  ! + c my_var ! "Hello World!" ।  & e& e  #
& ! order h  " + & a1Z p1   & e ! 6  & e  # " ! + script h" я  & !।

яskp 0
$ -
 - -W&:
- -W&:
3! 6!  & ! ( name)6Fn
6Fn  &! "! a&'i k  " + & ! 3! яskp e reserve
e ! !
+ ।  & ! (name)6F n
6F n  practice + &d!i  !  &&+ 3! !  &  #  e 1 !  '
 । 3! 8 #! 6!  &  # я#" iя  !  '  F  k t  & !  " 6 ! "shoe_size"। 3 #&
+ я 6a e& &I 3 &।

яskp  & ! (0 3! 7lucky, 99bottle e& 3charm ।
 0-99)  '# # + & !। 3 &&+   &8 ! । 3!:
&   +  & !  F
+ " &d  '# #   e&  & ! ! 3 e  a8 'b &'s + "+
'b$#   underscore  6:1  " + । 3!:
+ । 3! my_var, strong_man, happy_coder i"।

яskp E[\- u


  ( JavaScr i pt Funct i on Tut or i al i n Bangl a)
  : 
    

3 6! ! pg e aj" 1  "+ ei a8  ' "   $ &। a!! pg $# я (,
++,6ei6 i") '! e " яskp e '! p i ei। e 3 6! '! ' p1& + 1  "+ ei
a8  #&  ! 3$ + 6a u"।

E[\- ?
?
'! + e
#   . 3 #p a&s 1  3"kd 63n ! "  я  " &  + । 6#! &:t  я k t '! a ! 
&n । '! e 8  ei . & & !   ei я & &   3 ।
яskp '! e u+ !:
u+ !
'!  eiee .k n e head
$ e "  u"। '! " 7   #& +я। p1  '! e !  " + &
" 6 8 ! яskp .   " + & ।নিচে u+ ! 8  &9  6 s   + ।
01.<html>
02.<head>
03.<script type="text/javascript">
04.<
05.function popup() {
06.alert("Hello World")
07.}
08.>
09.</script>
10.</head>
11.<body>
12.<input type="button" onclick="popup()" value="popup">
13.</body>
14.</html>
p'!:
'! 1   8  browser  &#I F 3   '! &&+  " 3c। " 6   '! e !  F 3 "
e
  6 &" " &&+  " 6 । 3 +"#   pop up alert " 7  F  ei '!  "popup" '! & . "
6 । ei "{,}" b 
   '! . e 7! !8 !  ।  popup '! e . ei b 
"   +

8 !" e
 &9 e    $ " 6 3    & popup '! e "   alert '! &&+  । ei
alert '!       popup box + p'!  ।e
i + '! &&+ &  &a &9 " +  '! e "
'! e &&+ ।উপরের u+ !  F &
! click    popup box  F । &
! click    event & ।
e &9 6 &" a8  !   + F ।

яskp i
? u
  ( JavaScr i pt Event Tut or i al i n Bangl a)
  : 
    

яskp &9 6  '7" &6 + c e k" d  6!  .i! o & 6я  " +3  & ।  6! i

я
e !
p!&n ,   ! & я7&n  ! + &। 9!7 o & 6я " 7 t + c яskp i n । яskp e
i n + e! e я! 3 o & 6я e  1 & e u6 F# 
 ।নিচে яskp i n e F# u+ !   +  ।
1 e u k
2 o & 6я  . +o 
3 h" s ! u6 u  3    hover !  я! ।
4 eiee  e i!6#
&k   k  
5 e keystroke
яskp i ns e u+ !:
u+ !
яskp e F# 6#& !8 " ! F 3 8  a ! i n 
u6 "  s   + F। 6! 3! i n  ! ;
 &! "! F# я " + । 6!  a&'i i n  ! ;  " + &  ! HTML element i n e я! a 6k
 & e& i n 
   1  1 function я  & ।

  6#&& " a8 яskp i n &&+  F  3 ! &


! k    1  1 alert popup p'!  F ।এটা
F "onclick" яskp i n ।ei 8 ! u+ ! !    +   1 mouseover e& mouseout i n 3$  
+  ।
view source
print?
01.<html>
02.<head>
03.<script type="text/javascript">
04.<!--
05.function popup() {
06.alert("Hello World")
07.}
08.//-->
09.</script>
10.</head>
11.<body>
12.
13.<input type="button" value="Click Me!" onclick="popup()">
14.
15.</body>
16.</html>
p'!:

яskp 0s
? 0s
? u
  ( JavaScr i pt St at ement Tut or i al
i n Bangl a)
  : 
    

6! ic" яskp .   " 6 ! " & &' $ k t яskp .$#  6:1 6:1 s
n & &&:" d  $h" ।
e s
n  & 
 " 6 3  # ! । e s
n '!    " 6 । s
n !  '  3 Script
  & e&  & я  & ।

0s
? e 9p:
9p:
a!! pg $# я (,6ei6 i") e p !  '  " semicolon(;) &&+   + ।  яskp e   F
3 semicolon(;) e &&+ &8&8" &9 ! ।

0s
? e p
P:
p
P:
!m" s
n 3   & e ! 6 &" !, !"# ! ! p!   & '!  . i"   m& ।যাহোক F#
p s
n F 3  "  u d' a!#3 7 e  a6 + " 6:1 ।

ei a8   e& p s


n e kp 8 ! & " & 6 &" a8 e  &9  !   + &। !  e  p
 u l   + ।
1 n'! ('"
'" &)
& s
n
2 #6 (6#6#! &:t)
t s
n
3 a& яk (&si
&si ) !6# '! s
n
4  n (n&
n&)
n& s
n
5 ek 6'! (&"k
&"k)
&"k +n  s
n
n'! s
n:
3 6! 100  ! . 
 я "! , " & 6! m&"  F a  &!। ' 9  '" &(
 conditional) if/then
+ ।
statement 3 pg e k t a8 6  ! &&+ + ।
a1Z
 я")"
3 F# '" (condition) (a1 я" " + ,
+ " &   
& । 3
F#(6!  F a  )
a1Z 6!
 я" " 6 !!)1
'" (condition)(a1 6 !! 1 + ," &
+ " & 6! i я(
я  F a  ) " !।
   " 6 &! !।

6! Script  ! nt!   я! n'! s


n &&+   + 3 " a&s 6 pk " &n я   3 । 8 #!
6! ! & '9 F& F#   ! 6! website e home page e  " !। ei '" !  !  F e& 3 e
F#  ! + " & F#   ! я!  & '9 F& 6! website-e я
 ! p'" + &।
n'! s
n m n h j! Fa 6! 6! website  p"' a!#3 7 p!&n,9!7 ,. !  " 6 &!
!।

a, (,a- $bt)
t) 0s
?
6!  !o & !nt!6t 6h F !? 3 ! 6A! " & я!#! e
 e & 6A " + । p1  !nt!6t ! &! " 6
  t#  &!,  # 1#1#  я &!, #   & e
 &! " 6 6h  &!। 3 6! 100 !nt!6t 1  " &
& 99 ei &  " + &। e & & & ei я   & k ।

" & ! +я 6d"   F? +n ,pg e k t +я u6  F " яskp    3 । ei 6d" ! + c
"looping"।সঠিক 6 l! 8  looping e + 3 6! 6! F
#n Script  'k' 7 k a w 6 !"
 " 6 &!।

loop statement "n    3, ! '" " + c !।3 ! '" " + " & loop statement  '"  6 k
яskp .   я 6 !"  । яskp .   я 6 !"   6 '"  " &    + । 3 '" h 1 
" & pk  & '# # + । 3 '" 1 + " & loop (a1Z 6#! &:t я) 1  3 &।3   && + !nt!6 t 1
n  " & p1      & ! !nt6t &  F !। & 1  "+ e
     $ "   6# 6A &।
 3 & ! 1  " & looping &n + 3 & ।

a$
яk ($s) f-,a
\- 0s
?
0s
?
object model e # 3$ #&8 6 " ei statement $#  &&h" + । e #+# " 6!  3 object model m n ! &# I!
" &  !i e &9 6  !   + F।


? (n$f)
n$f) 0s
?
Comment statement d  6! 3 .   я $ " ! ! i .  buя 3 mn +o  1  & "  "
6 ! । " &  ! px я$ " 6 !   "  " i? " a !  ! F। 3&      p ' a!#" i!
& '#8#   ! я  я!  F 3 HTML comments e "। &   p я! " & .   3 $ "
6 ।

Single i! comment e #


 //(slash) 1 ।  a8 i! &'; '# # + (/*)  e& '9 + (*/)  ।6 &" "
e &9 &s "  !   + F।

яskp iE 0s
? u
  ( JavaScr i pt I f St at ement Tut or i al i n
Bangl a)
   яo !#  

яskp program  !#"


n  " 6!  n'! s
n &&+  " + & 3 6! program  dn ! " +3
 & । !! pg $# яo n'! s
n &&+  яskp " &"k ! ।  & e& F# p
data- u6 t  "If Statement" e + 3 d n !  3 ।u+ ! s #6 6! variable 1 " 6 3 "1 я
 । 6! ei k# d " 1 + 3 6! F
Script e 8  + я pg " 7  " 6 !। "Today is my
Birthday!" ei & "!i p'" + & 3! ! e&  6! яn ! ! + &।

яskp I F STATEMENT SYNTAX( 6h)


6h) :
If Statement e p8! # a' F " e n'! s
n e& a6  + ! ; . 3  3 6 !" + &। n'!
s
n + e! e s
n 3 ", 1 3i  । &' $ k t n'! s
n  ! F#   " &&h"
+ 3 F# "  # ! + ।উদাহরন s #6 &  3 e
   & 3 "  6! яn ! ! + ।

!  яskp .   + "  3 6 !" + & 3 If Statement '"  " + ।!  If Statement u+ !   +  ।
  e  я  " 6& 3 variable  7 e ! + ।
01.<script>
02.<!--
03.var myNum = 7;
04.
05.
06.if(myNum == 7){
07.document.write("Lucky 7!");
08.}
09.//-->
10.</script>
p'!:
Lucky 7!
u6 u+ ! variable !
 F myNum e& "  # 
  F " + c 7। Num e ! & "!m &I ।" 6      & 3 If
Statement' e '"  6# !# + c ! a1Z myNum ! 7 + c ! ("myNum == 7") 3 + " & e
  " &
& &!  &।  я( Lucky 7! )p'" + & ।
 ! n'! s
n  " F 3 .   If Statement ("document.write...") e  1 |; F "
 3 6 !" + F।

яskp I F STATEMENT: ELSE


e
  !   + F 3 3 '"  " + " &  & .  3 6 !" + ।কিন্তূ 3 '"  1 + " & 6! 6!
ic a!#3 7   .   3 6 !"  " 6 !।e
 + c If Statement e &8" a'(extension) " + c
Else clause ।

Else clause  я  3! n'! s


n  1 + । u6 u+ !  1   '#8# Elseclause 3$  F
e& myNum e  # (7 e 6 & " 10)6 &" !   F 3 "   n'! s
n  1 + ।
01.<script>
02.<!--
03.var myNum = 10;
04.
05.
06.if(myNum == 7){
07.document.write("Lucky 7!");
08.}else{
09.document.write("You're not very lucky today...");
10.}
11.//-->
12.</script>
p'!:
You're not very lucky today...

яskp e 9 iE u
  ( JavaScr i pt El se I f St at ement Tut or i al
i n Bangl a)
  : 
    

6#&&" a8 6!  '  F! 3, яskp- e  & basic If Statement " 7   3 । single If Statement e
e  a8 '" !d   k t basic If Statement  + "  1 ।
Else If statement + basic If Statement e e extension 3 8  6! a !$#  conditional
statement " 7  " 6 !।

яskp ELSE I F e uP' -:


uP' -:
8 #! 6!  c! 6! F
"student" script  customized  я  p'" + 3 !   o & 6я 
&&+  F। 3 6! e  a8 custom  я 1  " & extension + & 6! Else If statement 
&&+  " 6 !।
01.<script>
02.<!--
03.var visitor = "principal";
04.
05.
06.if (visitor == "teacher"){
07.document.write ("My dog ate my homework...");
08.} else if (visitor == "principal") {
09.document.write ("What stink bombs?");
10.} else {
11.document.write ("How do you do?");
12.}
13.//-->
14.</script>
p'!:
What stink bombs?

ia grt,a-R $m :


$m :
1 Else If statement &&+    $ 6!  a&'i 8 ! If Statement &&+  " + &।  !Else
If statement  + c basic If Statement e &8" a'।
2 6! a ! $#  Else If statement 1 " 6 , u6 u+ !   t Else If statement e &&+  F
" & 6! 6! ic " Else If statement &&+  " 6 !।

яskp 0' i a, u


  (
u
  ( JavaScr i pt Whi l e Loop Tut or i al i n
Bangl a)
  : 
    

while loop + e advance pg 6d" 3 8  ! я & &  " 6 ! 3! 6! n'! s
n 
" + & । 3o while loop e 8 ! &&+ e
# я । e a8 6!    &  & яskp e while
loop " 7   3 ।

яskp WHI LE LOOP e $f%f:


$f%f:
яskp while loop e p8! # a' F।

1 while loop e .  3 6 !" +o  я! a&'i n'! s


n   " + " + &।

2 while loop e . & ! b 


"{ }" 8 !  3  я 6 !" + & 3 n'! s
n  " + ।
3! while loop '# # + , яskp     3 condition statement  " + F ! ।যদি " + " & & !
b 
"{ }" e  8 .  3 6 !" + & ।কোড a ' ' 9 "}" while loop  & condition
statement e  3 e& & '# # + ।

3 condition statement  & " + " & 6! !o while loop + " & +  " 6 &! ! । "i while
loop &&+  " +o  u"।

9n - WHI LE LOOP e uP' -:


uP' -:
e u+ !  ! + F  & basic while loop " 7 e 3 । 3 document.write  10 &  3 6 !"  F ।
" 6 loop statement + " & + e  F ।
01.<script type="text/javascript">
02.<!--
03.var myCounter = 0;
04.var linebreak = "<br />";
05.document.write("While loop is beginning");
06.document.write(linebreak);
07.
08.while(myCounter < 10){
09.document.write("myCounter = " + myCounter);
10.document.write(linebreak);
11.myCounter++;
12.}
13.
14.document.write("While loop is finished!");
15.</script>
p'!:
While loop is beginning
myCounter = 0
myCounter = 1
myCounter = 2
myCounter = 3
myCounter = 4
myCounter = 5
myCounter = 6
myCounter = 7
myCounter = 8
myCounter = 9
While loop is finished!

  variable myCounter  0 + " '# # + 3 10 + " F


,  while loop e .   3 6 !"  " 6 ।  #
0 3 buя p'" + । " 6 variable myCounter 1  &:d 6 e& while loop 6#!  '# # + ।
1 3 10 + " F
 while loop e .  3 6 !" + & । pk   " 1 & ।

myCounter 3! 10 3 10 + " F


!  k t while loop e .  3 6 !" + & ! । "i  # 10 p'" + !। 
'9  # + & 9 p'" + F।

яskp E a, u
  ( JavaScr i pt For Loop Tut or i al i n Bangl a)
  : 
    

яskp  #6 a!! pg $# я  #6 e " । e


 &&+ + 1 
3! 6! a !& ! ! ;( set of operations) я   p я! + e& ! ; . e 8  p "& я  
6 F# я! &:d 6 ।

яskp E a, e $f%f:
$f%f:
яskp  #6 e   $# t# 6#! &9 F।
1 counter variable  '#8# t  #6 e k t &&+   я! " 7 e + F। ei counter variable d  $!!  
+ 3 "&  #6 e 6#! &:t 
&। i + counter variable e 8 !   ।
2 conditional statement  dn ! 3  #6  a!& "  я (executing)! я" + &  + & !। F# u6 e
counter variable  (check)  ।
3  #6 e increment ' ! p " loop & 6#! &:t 6 counter variable e &:d + ।ei &:d 6 !  .  
1 ।

4  #6 e 8  p " loop & 6#! &:t я! ! ; .  я(executed) 6 !" + ।

e
 ad# "  ! + " 6 " & 1-3 &i ei i ! . e я! 
। e  ! + c 
#6 standardpg e a!#'7 !।যা designer $d a!#&  " 6 ।  #6 e 8  F# s e& &':  + " k
6o  3 ।

яskp E a, e uP' -:
uP' -:
ei u+ ! 8    & 3  & 8 !  #6 " 7   3 e&   counter e value p'" + & 3"k!
! counter 5 e 6F । loop  . p1 i ! "! n (i = 0; i < 5; i++)item e   & '9  ! 3$  
u"। e$#   #6 e $# t# 6#! &9 3 u6 1 + " 3 6 n  !   + F।
01.<script type="text/javascript">
02.<!--
03.var linebreak = "<br />";
04.document.write("For loop code is beginning");
05.document.write(linebreak);
06.
07.for(i = 0; i < 5; i++){
08.document.write("Counter i = " + i);
09.document.write(linebreak);
10.}
11.
12.document.write("For loop code is finished!");
13.</script>
p'!:
For loop code is beginning
Counter i = 0
Counter i = 1
Counter i = 2
Counter i = 3
Counter i = 4
For loop code is finished!
counter variable ! (name) i    ad# " $ " 6 " & e
 &&+ +  F। 9 !  ! । i + c
loop counter e default (name) ! । a!! ! variable ! + c j,k,x,ye& z।
ei u+ !   counter  p1  0 " ("i = 0;") 
  + F। " 6 conditional statement 
("i < 5;")
  + F।   counter 5 + " F
"i  #6 e .  я(executed) 6 !" + F ।
 #6 e .  я(executed) 6 !" +o  6 ("i++") &:d 
F। counter i ! 1 + & " 7   + F
।তারপর    + 3 5 e  F
+ " & 6#!   #6 e .  я(executed) 6 !" + ।ei looping  "
1  3"k! ! counter i 5 e ! + c । ni 5 " 5 + " F
!   #6 e .  я(executed) 6 !" +o 
&n + 3 &।

яskp n$f ( JavaScr i pt Comment s Tut or i al i n Bangl a )


  : 
    

6!  !o Script & pg a"7 "   F! 3 F   $   F! ni ! 8 ! !i 3 ei .  6! 
 &!।6! m&" # $ F!   "  F !। я!  n (Comments)  u"।
3! 6! .  ! "! 6! a ! я я 1 " 6 " & &   +  .  1 F#  n
(Comments)an k   3 6!  &  &  + " 3 c। e
 '#8# 6!  6 &" " s !  " +3  & " ! ,
6! 3 6! . u  ! " & " o #& + я . &#I " 6 &।  n(Comments) e   &a #&8 + c
3! 6!  . # t #     n(Comments)e + 3 a!" . #  " 6 &!।
ei a8 6!   &  & #i 8 !  n(Comments) JavaScript e   3
1 single i!  n( comments )
2 multi- i!  n( comments )
SI NGLE LI NE COMMENTS p& W  :
 :
яskp e single i!  n( comments ) " 7  " + 6!  . & text e  ! # s (slashes) "//"
 " + &। я 6 !" & p'" + & !। 3! 6! ei # (slashes) "//"  &! "! " .! 6 '  text p'" + &
!।3"k! ! 6 &" i ! 3 ।
1.<script type="text/javascript">
2.<!--
3.// This is a single line JavaScript comment
4.
5.document.write("I have comments in my JavaScript code!");
6.//document.write("You can't see this!");
7.//-->
8.</script>
p'!:
I have comments in my JavaScript code!

MULTI - LI NE COMMENTS p& W  :


 :
3o single i!  n (comments ) 
# u6 7 " & 3! 6! ! &a a ' .  ak  " !  k t
single i!  n( comments ) e &&+ !o !o &I + a । e  &a 8 !  n( comments )
e я! яskp multi- i!  n( comments ) &&+   u"।3 '# # + /*  e& '9 + */  ।
01.<script type="text/javascript">
02.<!--
03.document.write("I have multi-line comments!");
04./*document.write("You can't see this!");
05.document.write("You can't see this!");
06.document.write("You can't see this!");
07.document.write("You can't see this!");
08.document.write("You can't see this!");
09.document.write("You can't see this!");
10.document.write("You can't see this!");*/
11.//-->
12.</script>
p'!:
I have multi-line comments!

яskp af
u
  ( JavaScr i pt Ar r ay Tut or i al i n Bangl a)
  : 
    

a + e  & 3 ! я  8 a !$#   & я   " 6 । a ! pg a! $# я a   F 3
яskp + " n ! ।

3! 6!  яskp e a &&+  &! "! !  6 n$#  a&'i  !  u"।
1 a + c e
 & '9 8 !  &
2 array name &&+   8  a e  #  я   + । a " a&s! h  6! ic a!#3 7
b 
 # я   " 6 !। 3!: myArray[2] = "Hello World";
3 array name e 8   # e& " a&s! & 3 ।যেমন: myArray[2]

4 яskp e a e я! built-in function F। "i &&+    $   !  u"।

яskp af
p& W - :
- :
8 !  & " 7   + " a " 7   F#
 n।  ! JavaScript e  & e& property F 3 a e
+" |;। !"# ! a " 7  " 6! special function &&+  " 6 !। !  u+ ! 8   ! + F 3
 & 6! 8 ! a " 7  " 6 &!,  !  # я  " 6 &!, i  # !d  " 6 &!।
01.<script type="text/javascript">
02.<!--
03.var myArray = new Array();
04.
05.myArray[0] = "Football";
06.myArray[1] = "Baseball";
07.myArray[2] = "Cricket";
08.
09.document.write(myArray[0] + myArray[1] + myArray[2]);
10.//-->
11.</script>
p'!:
FootballBaseballCricket
k 6! b 
 # position h     6! ic a!#3 7  # &  " 6 F!।

яskp af
9R[:
8 #! 6! a  &d  a!# я " (sort) ! "   a e sort method e 8   " 6 ।
01.<script>
02.<!--
03.var myArray2= new Array();
04.
05.
06.myArray2[0] = "Football";
07.myArray2[1] = "Baseball";
08.myArray2[2] = "Cricket";
09.
10.
11.myArray2.sort();
12.
13.
14.document.write(myArray2[0] + myArray2[1] + myArray2[2]);
15.//-->
16.</script>
p'!:
BaseballCricketFootball

яskp e R E\- u


  ( Javascr i pt Al er t Funct i on Tut or i al
i n Bangl a)
  : 
    

3 6! o & buя e яskp ek   ! 1  "+ 6! Alert  " 6 &! !। яskp e 
 + c e

.  $ &k 3 pops up e&  " buя ui n + " :;  9!  । o & buя  Alert  я 6a " &8  ।

r%- +  POPUPS / ALERTS $f$'  $:


 $:
!  a&s k t JavaScript alert &&+   3 ।

1 6! 3 !Y" + " ! 3 &&+  7(user) website e ! F#    $  я  !।

2 F# &9 m n &&+  7 (user)"   " । 3!:ei  я  "   " 6 !


"the following page contains humor not suitable for those under the age of 14"
3 e
 # + $ F। e &6 6! &&+  7 (user) я! " !।
4 F#  я &6 !Y" + " &&+  7 (user) яj  " 6 !। 3!: 3 "  &a # k &6 i!  "
я + " & 6! "   & яj  &! 3 "  # k &6 !Y" " & "  ei d n o" 6a &।

9n - яskp e R:


8 #!   e " 7  F 3 ! я!$!  &  + F &a ! p! # k &6 ।ফলে я!$ !  1 # k &6 !Y"
  я!   e alert 3 o &i
e 3$  " + &। !   . alert 3#k   + F 3 ! eiee e&
&
! onClick event 3#k + F।
1.<form>
2.<input onclick=
3."alert('Are you sure you want to give us the deed to your house?')"
4.value="Confirmation Alert">
5.</form>
p'!:
String a1Z alert e b 
" 3   " alert box e " pn +  F &
! k    1  1  
 ! p'" + &।
яskp -ER E[\- u
  ( Javascr i pt Conf i r m Funct i on
Tut or i al i n Bangl a)
  : 
    

JavaScript confirm '! e& JavaScript alert '! p ei ।e


 e
 F
.  $ &k 3 o & 6я e
 !   :; 6"   я! p'" + ।confirm box 3 alert box + " n ।এটা &&+  7  # a6'!  :

1 666  я 3 "  confirm  "  " & OK p  " + &।

2 & 666  я  1 e" ! + " & cancel p  " + &।

! F# !Y"   я! confirm '!  p i &&+ + 1 । ei $# t# 6#! я website e 8  mn   + ।
&&+  7$! ! F# submission e& &&+  7  &jp p!  3 "  3    k  F " 8  a!
website e 3" ic#  !।

JAVASCRI PT CONFI RM e uP' - :


01.<html>
02.<head>
03.<script type="text/javascript">
04.<!--
05.function confirmation() {
06.var answer = confirm("Leave webcoachbd.com?")
07.if (answer){
08.alert("Allah hafiz!")
09.window.location = "http://www.google.com/";
10.}
11.else{
12.alert("Thanks for staying with us!")
13.}
14.}
15.//-->
16.</script>
17.</head>
18.<body>
19.<form>
20.<input type="button" onclick="confirmation()" value="Leave webcoachbd.com">
21.</form>
22.</body>
23.</html>
p'!:
 .  a '   k  #!।  !   e  я+ ("Leave webcoachbd.com?")
'!  . F। JavaScript popup window " 7  F 3 # &9 6Fn   a6'! F। яskp  #
  ! 3 !  &&+  7 ! &
! k  &।

3 &&+  7 OK k  " &  # 1   &, 3 &&+  7 cancel k  " &  # 0   &।  
answer e  8 ei  #  я । ei answer  confirm '! e ! + & 
 ।

Answer  # я  6 ,  Answer  n'! s


n + & &&+  F। 3 Answer 'i! Fa a! F# +
" &   &&+  7    webcoachbd.com + " a! 1o 6h  &। 3 Answer ! 'i! + " &
&&+  7   i
1 &  ! &&+  7 cancel &
! k  F।

p" k ti яskp alert box p'" + & 3 &&+  7  я! &  + " 3 c। 3 6!   i
 "$  " !
" & "Bye bye!" p'!  &  3   i
1 " ! " & "Thanks for sticking around!" p'!  &।

ei a8   p1 & " window.location property &&+  F। ei &9 6 &" a8  !  
+ F।

яskp pm u


  ( Javascr i pt Pr ompt Tut or i al i n Bangl a)
  : 
    

яskp pm
e &&+ &"  !   3 । яskp pm
e u d' + c &&+  7(user) + " "1 g+   3 " ei
"1$#   e &&+   3 3  &&+  7 (user) &k$" a!##" :; + &।
 $  !   prompt e &&+  $ F  ! personal webpage e ! яj   + "। " 6 "1   6
6!  a&!  я   + " 3!: "Welcome to My Personal WebPage ferdous alam!" (e ! 6! 3
!  &! " p'" + &)
яskp pm
#&  я  $ ! e
 a !   F & k  । " & ' я! e ! ' &।

9n - JAVASCRI PT PROMPT:


01.<head>
02.<script type="text/javascript">
03.<!--
04.function prompter() {
05.var reply = prompt("Hey there, good looking stranger! What's your
name?", "")
06.alert ( "Nice to see you around these parts " + reply + "!")
07.}
08.//-->
09.</script>
10.</head>
11.<body>
12.<input type="button" onclick="prompter()" value="Say my name!">
13.</body>
p'!:
" & "1 g+   &   u6 + c eiee  e &&+ ।

яskp p? E[\- u


  ( Javascr i pt Pr i nt Funct i on Tut or i al
i n Bangl a)
  : 
    

JavaScript print '! ei я  3!  6! buя ui n i !# print a6'! । JavaScript
print '!  o & 6я e !
n  &&+  7 (user)pn 6h  ।
a !  ei '!  a!1  !  ।a !   F 3  mu
 m n  3 ! ! "  k t ei a6'! 1 a ! #&8
+ &।

JAVASCRI PT PRI NT SCRI


SCRI PT - WI NDOW. PRI NT( ) :
JavaScript print function 3 window.print() e o & 6я  pn  ।ei '!  eiee &
!  &
3 onClick event e 8  я  &।
view source
print?
1.<form>
2.<input type="button" value="Print This Page" onClick="window.print()" />
3.</form>
p'!:

яskp ,-:-
PR\ $  1i
k u
  ( Javascr i pt Redi r ect Tut or i al
i n Bangl a)
  : 
    

8 #! 6! 6! i


  ! !"# ! . i! !  ! "  c!। i
.яi!     I  I e
 p я! + " 6 3
6! e
 6 я   '! 6 &" !  &! a1Z   e
 6 я   '! 6 &" !  &!। e& &6 JavaScript
redirect 6!  +3  &।
3! 6! o & 6я    ! + & "! ei 6 &" ! &&+  7   " i " 6 !।  k t  u6 + c 6# "!
location e 6я redirect   a1Z 6i!:!  '   । " 6 F#  &&8 ! &&+  7 !"# ! a&s!   " 6 &।
JavaScript redirect e 8  6! e&  " 6 !।

JAVASCRI PT WI NDOW. LOCATI


LOCATI ON:
! 6я  . + & JavaScript property window.location e + 3 ! nt!   3 । window.location " 6
"=" he& " 6 !"# ! URL 
 6! &" ! 6я 1  ! ; 6 я 3 " 6 !। 6! 3 !  &&+  7
6! i
t  1  1 redirect + www.google.com e  " & !  .  #!।
1.<script type="text/javascript">
2.<!--
3.window.location = "http://www.google.com/"
4.//-->
5.</script>

JAVASCRI PT TI ME DELAY
DELAY
e
 ! mk 6 s" " &' u6 7।
1.3 ! 6 я   '! 6 &" !  ! "+ "Update your bookmarks " e 8 ! e
  я  !"# !   ' !
! 3 " 6 !।

2.! ;  6 6 3 6! 6! o &i


 '  " !।

!  u+ !   " k  tizag.com e e


 6 я ! 3 &।a1Z !"# ! 6 я   '! tizag.com e ‚ 6я।
01.<html>
02.<head>
03.<script type="text/javascript">
04.<!--
05.function delayer(){
06.window.location = "../javascriptredirect.php"
07.}
08.//-->
09.</script>
10.</head>
11.<body onLoad="setTimeout('delayer()', 5000)">
12.<h2>Prepare to be redirected!</h2>
13.<p>This page is a time delay redirect, please update your bookmarks to
our new
14.location!</p>
15.
16.</body>
17.</html>
p'!:
Time Delay Redirect
Time Delay a1Z F#   । e
 6 "   JavaScript e setTimeout function  a&'i &&+  &।
3 function delayer()  5  n (5000   n)  " я   " i  k t   setTimeout 
 & 3
# &9 F।

1. 'delayer()' –   i setTimeout()function  ! ;  6 3!  я 6 !" + ।

2. 5000 -    n  ।   i function delayer()   я 6 !" +   $


setTimeout() function  5000 -   n   #।

WEB PAGE REDI RECTI ON:


ON:
3! 6! o &i
e URL 6 &" !  " ! & i  !"# ! location/a&s ! e   " !  k t JavaScript
redirect &&+   3 । 3 e! + 8 ! HTML hyperlink e 8  6я & URL  p   3 " &
JavaScript redirect &&+   u" ! ।

яskp ,, +, ui
?1 u
  ( Javascr i pt Popup Wi ndow Tut or i al
i n Bangl a)
  : 
    

e a8   ' &  & i


e 666 " 7   3 ।   3& я $   & я $ я! 666 ui n " 7
 &  ! a31 666 ui n &&+  7  & k  ! + &। 3 6! a" k "1  " ! & 6! ! !"# !
window o 6! ! 3 eiee e!
$ (hyperlink) ! ।  k t popup window &&+   u"।
JavaScript window.open Function:
eiee e!
$ e &&+ Fai   window.open() function  + 3 !"# ! browser window " 7
 " 6 ।   e function " 7  " 3 window.open() function   &&+  ।
01.<sup><head>
02.<script type="text/javascript">
03.<!--
04.function myPopup() {
05.window.open( "http://www.google.com/" )
06.}
07.//-->
08.</script>
09.</head>
10.<body>
11.<form>
12.<input type="button" onClick="myPopup()" value="POP!">
13.</form>
14.<p onClick="myPopup()">CLICK ME TOO!</p>
15.</body>
16.</sup>
p'!:
CLICK ME TOO!
JavaScript Window.Open Arguments:
window.open() function  8    popup window  customize  " 6 । window.open
function e "! 8 ! 3#k F।
1 webpage e URL o 6!  " ।

2 window e text e !  я! я!।

3 e
 m string 3 window e n properties 8 !  ।

window e ! ! e
 $# t# 6#! &9 3 6! e  яskp e + 8 6  !  " !। 3 + ei # 3$ ei
a8 !i ।   e ! e &n properties m n  6"  &। !  $# t# 6#!  !   + ।

1 dependent – 3 6! browser window  &n + " & Subwindow  &n + &।

2 fullscreen - fullscreen mode e browser p'" +o ।

3 height – !"# ! window e height, pixels –e ।

4 width - !"# ! window e width, pixels-e ।

5 left - screen e &6' + " Pixel offset।

6 top - screen e u6 + " Pixel offset ।


7 resizable – &&+  7  window resize   a!#"   & &&+  7  window resize   1  & "
।

8 status - status bar p'!   & !  ।

Dependent, fullscreen, resizable,e& status &$#  ON/OFF properties e u+ !। 6! "   'i! 

 &n  " 6 ! & e 


 a!  " 6 !। e& e ei #i  e  I  a! !  !i।

un& яskp ,,+, ui


?1:
ui
?1:
01.<head>
02.<script type="text/javascript">
03.<!--
04.function myPopup2() {
05.window.open( "http://www.google.com/", "myWindow",
06."status = 1, height = 300, width = 300, resizable = 0" )
07.}
08.//-->
09.</script>
10.</head>
11.<body>
12.<form>
13.<input type="button" onClick="myPopup2()" value="POP2!">
14.</form>
15.<p onClick="myPopup2()">CLICK ME TOO!</p>
16.</body>
p'!:
CLICK ME TOO!

яskp & % u


  ( Javascr i pt Dat e Tut or i al i n Bangl a)

  : 
    

Date object #&i $# t# 6#! 3! 6! "  p'!  " ! a1& e p calculation e k t timestamp &&+
   । яskp e &&+  7 computer clock a!#3 7 Date object " 7   + ।
3! Date object " 7   + mu
 e an 7!  a!#3 7 "! e
 #&i $# t# 6#! 3 u  &n    & u
3 n time zone e a&s! 

яskp & % (+я


 $&R- 9 )
9 ) :
  яskp Date object e k" &a " +я F#   u"। 6! 3 Date constructor (3 Date object
" 7  )  ! 3#k & '" ! ! " & e &&+  7 computer clock a!#3 7 Date object " 7  &।
1.<h4>It is now

2.<script type="text/javascript">

3.<!--

4.var currentTime = new Date()

5.//-->

6.</script>

7.</h4>

p'!:

I t i s now

!  p'!  F !  !   Date object e ! 6d" a& m!  !।

яskp 9 :
9 :
Date object " 7 + F e&    & F 3 &" ! "   8 !  । "1 6o  я! 3   p'!  &
я!   F# '! &&+  &। !  u l   + ।
1. getTime() –   n $d! since 1/1/1970 @ 12:00 am
2. getSeconds() –  n $d! (0-59)
3. getMinutes() – !
$d! (0-59)
4. getHours() – n $d! (0-23)
5. getDay() – p + ! $d! (0-6). 0= && , ... , 6= '!&
6. getDate() –   ! $d! (0-31)
7. getMonth() –  $d! (0-11)
8. getFullYear() –  .я
&F (1970-9999)
e! "  &9  "1 p'!  " 6 &। !  u+ !   getDate, getMonth, e&getFullYear '! &&+
 F।
01.<h4>It is now

02.<script type="text/javascript">

03.<!--

04.var currentTime = new Date()

05.var month = currentTime.getMonth() + 1

06.var day = currentTime.getDate()

07.var year = currentTime.getFullYear()

08.document.write(month + "/" + day + "/" + year)

09.//-->

10.</script>

11.</h4>

p'!:

I t i s now

k  #! 3 month variable (currentTime.getMonth() + 1) e  1 1 3$   + F । 3 +"# я!#  7  0 e&


. m  11 !m "i ei  8!  " month variable e  1 1 3$   + F । 1 3$   6 я!#  7 
1 e& . m  12 !m + F।

яskp ($&R-)
-) 9 x :
x :
  e! Date p'!   6 & " e! e
  
p'!  & 3 .я
 a "  3 । HH:MM AM/PM (H
= n , M =!
)।
01.<h4>It is now

02.<script type="text/javascript">

03.<!--

04.var currentTime = new Date()

05.var hours = currentTime.getHours()

06.var minutes = currentTime.getMinutes()

07.if (minutes < 10){

08.minutes = "0" + minutes

09.}

10.document.write(hours + ":" + minutes + " ")

11.if(hours > 11){

12.document.write("PM")

13.} else {

14.document.write("AM")

15.}

16.//-->

17.</script>

18.</h4>

p'!:

I t i s now
3 hours or minutes variable 10 + "  + " & 7 8 9 i" " & ei   ! 'i! & !  a1Z 07, 08,
09 i"। 3  + 1:01 am " & 1:1 am     !।

яskp ER 0


1\- ( JavaScr i pt For m Val i dat i on Tut or i al i n
Bangl a)
  : яo !#
  яo !#  

Order g+!  ,guestbook entry  , & a!! .


 3$#   8  &
 ,eя! iuя 3 e$# am#! 
&
 "+ e  &a I    F# !i। яskp e 8  e& I   ea " 6 !। ei '  &  + "
 .'!"।
яskp   .'! e! e ' 3 8  &&+  7$! .
 &
   $ "  e "1  3i
 ।яskp 6!  +3 7 e 
  & e& 
 &&+  7$!  я! & 3 " "1 # & am#! F e&  o
& & 3  &   8!  " 6 &। e a8   F# &   .'! !  !  &। !  &9
$#      & 3i  & " 8 6 8 6  !   + F।

1.e
 text input   !  ! ।

2.3 text input  &  + ।

3.3 text input  & & d + ।

4. 3 text input  & alphanumeric character (numbers e& letters) e + ।


5.3 text input  " h  character 1 । &9    3! username & password e length 
restriction   1  a1Z " ! ;  & & d &' + & !।
7.i i e <  &8 !
i"  я!   .'! &&ƒ" + ।

ER 0
1\- :NON-
NON- EMPTY 06  :
 :
e
 e
 common
i 6   .'! । 6! !Y" + " 6 &! 3 &&+  7 eiee l e  8 .
   F
!। eiee i!6#
  !  ! e& !d я! !  & яskp .   + ।
01.// If the length of the element's string is 0 then display helper message
02.function notEmpty(elem, helperMsg){
03.if(elem.value.length == 0){
04.alert(helperMsg);
05.elem.focus(); // set the focus to this input
06.return false;
07.}
08.return true;
09.}

notEmpty function      3 eiee input e 3     6A &  ! F#  F !। elem +
HTML text input   ei '! 6A & । яskp strings e built in property F। "  8 e +
length property । 3 string e length  return  । e
 &a . elem.value 3 input e " string 

  ।  .   length 3#k + । ' 9 a elem.value.length ।
elem.value.length 3 'i! ! + &  ! + " &   " &  6i। a!1 helperMsg e + 3
&&+  7  ! e alert  я p '" + । 1 &&+  7 # + F ei  я " !  '  । e
 1 + &
 6o  3 ।
u+ !:
01.<script type='text/javascript'>
02.function notEmpty(elem, helperMsg){
03.if(elem.value.length == 0){
04.alert(helperMsg);
05.elem.focus();
06.return false;
07.}
08.return true;
09.}
10.</script>
11.<form>
12.Required Field: <input type='text' id='req1'/>
13.<input type='button'
14.onclick="notEmpty(document.getElementById('req1'), 'Please Enter a
Value')"
15.value='Check Field' />
16.</form>

p'!:

Required Field:

ER 0
1\- - 9$ i-,a 9[%f - & 06   яn:
яn:
3 u k.
.,! !m , zip . i" i!6#

k
  " & 6!   . 8  !Y"  " + & 3 i!6#

k

+ &  । e&    d" u6 + c 3 input e string  # + &  3 regular expression + c /^[0-
9]+$/ e& " match  & 3 string + &   " an"6 k e character e + ।
01.// If the element's string matches the regular expression it is all
numbers
02.function isNumeric(elem, helperMsg){
03.var numericExpression = /^[0-9]+$/;
04.if(elem.value.match(numericExpression)){
05.return true;
06.}else{
07.alert(helperMsg);
08.elem.focus();
09.return false;
10.}
11.}

u6  . " p " string + e function 3 ! match । ei function  &&+   " 6 ! 3
string e  1 match  F !।     e & &&+  " 6 3!:
elem.value.match(e ! expression)
  3  " i 3 i!6#
string  &  F !,  k t       я! regular expression " 7
 F 3 numericExpression + & я  ।
  regular expression e +" match function &&+  F। 3 e
 numeric + 1 
" &match function  " &  6&।   isNumeric function o " &  6&। 3 i!6#
string 
&d & a! characters + " &   expression  &1 + &।  helperMsg  p'" + & e& 1 &  6&।
u+ !:
01.<script type='text/javascript'>
02.function isNumeric(elem, helperMsg){
03.var numericExpression = /^[0-9]+$/;
04.if(elem.value.match(numericExpression)){
05.return true;
06.}else{
07.alert(helperMsg);
08.elem.focus();
09.return false;
10.}
11.}
12.</script>
13.<form>
14.Numbers Only: <input type='text' id='numbers'/>
15.<input type='button'
16.onclick="isNumeric(document.getElementById('numbers'), 'Numbers Only
Please')"
17.value='Check Field' />
18.</form>
p'!:

Numbers Only:

ER 0
1\- - 9 i-,a $zR  - & 06  
  яn:
яn:
ei isAlphabet function  isNumeric function e " " & &"k '#8# t regular expression 6 &" !
k t।   " match function  &&+  F । e !       6 & " &d   &।   3
 " i   string  '#8# &d 8 !  &, " &   lowercase e& uppercase u k t expression ! ;
 &।
01.// If the element's string matches the regular expression it is all
letters
02.function isAlphabet(elem, helperMsg){
03.var alphaExp = /^[a-zA-Z]+$/;
04.if(elem.value.match(alphaExp)){
05.return true;
06.}else{
07.alert(helperMsg);
08.elem.focus();
09.return false;
10.}
11.}
u+ !:
01.<script type='text/javascript'>
02.function isAlphabet(elem, helperMsg){
03.var alphaExp = /^[a-zA-Z]+$/;
04.if(elem.value.match(alphaExp)){
05.return true;
06.}else{
07.alert(helperMsg);
08.elem.focus();
09.return false;
10.}
11.}
12.</script>
13.<form>
14.Letters Only: <input type='text' id='letters'/>
15.<input type='button'
16.onclick="isAlphabet(document.getElementById('letters'), 'Letters Only
Please')"
17.value='Check Field' />
18.</form>

p'!:

Letters Only:

ER 0
1\- - 9 $zR e$[ 9[%f 06   яn:
яn:
  isAlphabet e& isNumeric function u  et  e function e #6n "  F 3 d   
i!6#
&d o  u    " 6 । 3!: isAlphanumeric
01.// If the element's string matches the regular expression it is numbers
and letters
02.function isAlphanumeric(elem, helperMsg){
03.var alphaExp = /^[0-9a-zA-Z]+$/;
04.if(elem.value.match(alphaExp)){
05.return true;
06.}else{
07.alert(helperMsg);
08.elem.focus();
09.return false;
10.}
11.}

ER 0
1\- - CHARACTER e pPxRf $ LENGTH e $n-
mn:
$n-
mn:
Character !m &8! 98   &&+  7 + я field e p &'  " 6 &  ap† .
 p" 8   3 । 3!
6! я !! 3 zip . 5  +o  u"  k t 2  +o  u" ! । !   lengthRestriction function 
" 7  F  !   #  8  
k
.
 i!6#
  я! minimum e& maximum Character e 
!8 !   F।
01.function lengthRestriction(elem, min, max){
02.var uInput = elem.value;
03.if(uInput.length >= min && uInput.length <= max){
04.return true;
05.}else{
06.alert("Please enter between " +min+ " and " +max+ " characters");
07.elem.focus();
08.return false;
09.}
10.}

u+ !:
01.<script type='text/javascript'>
02.function lengthRestriction(elem, min, max){
03.var uInput = elem.value;
04.if(uInput.length >= min && uInput.length <= max){
05.return true;
06.}else{
07.alert("Please enter between " +min+ " and " +max+ " characters");
08.elem.focus();
09.return false;
10.}
11.}
12.</script>
13.<form>
14.Username(6-8 characters): <input type='text' id='restrict'/>
15.<input type='button'
16.onclick="lengthRestriction(document.getElementById('restrict'), 6, 8)"
17.value='Check Field' />
18.</form>

p'!:

Username(6-8 characters):

ER 0
1\- - SELECTION p& W  :
 :
e ! madeSelection function  &&+   + F। &&+  7 eiee select input + " 3 ! &9 select
 " 6 &!। 6! 8 ! trick + & &&+  7 я! p1 a6'!  +3 7 prompt + &  " 6 !। p1
a6'! + & select input- e F#  " 6 ! 3!: "Please Choose" ।
01.function madeSelection(elem, helperMsg){
02.if(elem.value == "Please Choose"){
03.alert(helperMsg);
04.elem.focus();
05.return false;
06.}else{
07.return true;
08.}
09.}
u+ !:
01.<script type='text/javascript'>
02.function madeSelection(elem, helperMsg){
03.if(elem.value == "Please Choose"){
04.alert(helperMsg);
05.elem.focus();
06.return false;
07.}else{
08.return true;
09.}
10.}
11.</script>
12.<form>
13.Selection: <select id='selection'>
14.<option>Please Choose</option>
15.<option>CA</option>
16.<option>WI</option>
17.<option>XX</option>
18.</select>
19.<input type='button'
20.onclick="madeSelection(document.getElementById('selection'), 'Please
Choose Something')"
21.value='Check Field' />
22.</form>
p'!:

Selection:

ER 0
1\- – i
i 0
1\-:
0
1\-:
e! 6!   & 3, &&+  7 i i  &8 ! "  & 6!   " 6 &! ।
a&'i i i an"6 k @ sign e& dot (.) 1 & 3 ! @ sign  i i e p1 Character + & ! e& ' 9 dot
(.)  @ sign e 6 a&'i e Character e + &।

Valid u+ !:

• bobby.jo@filltank.net
Invalid u+ !:

• @deleted.net - @ sign e  $ ! characters !i।


• free!dom@bravehe.art - invalid character !
• shoes@need_shining.com - domain name e underscores &&h" + !।
01.function emailValidator(elem, helperMsg){
02.var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
03.if(elem.value.match(emailExp)){
04.return true;
05.}else{
06.alert(helperMsg);
07.elem.focus();
08.return false;
09.}
10.}

u+ !:
01.<script type='text/javascript'>
02.function emailValidator(elem, helperMsg){
03.var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
04.if(elem.value.match(emailExp)){
05.return true;
06.}else{
07.alert(helperMsg);
08.elem.focus();
09.return false;
10.}
11.}
12.</script>
13.<form>
14.Email: <input type='text' id='emailer'/>
15.<input type='button'
16.onclick="emailValidator1(document.getElementById('emailer'), 'Not a Valid
Email')"
17.value='Check Field' />
18.</form>

p'!:

Email:

ER 0
1\- – 9$ e ah
&R:
p "  e яskp event F 3 ! onSubmit । e
 я  3! e &
&
! k   + । 3 ei event
 0 & 1 return  " &   &
+ & !। 3 e
 1 & " & return  " &  &
+ &।  &
e
k t e ! Validator '! &&h" + F।

eiee  .:

01.<form onsubmit='return formValidator()' >


02.First Name: <input type='text' id='firstname' /><br />
03.Address: <input type='text' id='addr' /><br />
04.Zip Code: <input type='text' id='zip' /><br />
05.State: <select id='state'>
06.<option>Please Choose</option>
07.<option>AL</option>
08.<option>CA</option>
09.<option>TX</option>
10.<option>WI</option>
11.</select><br />
12.Username(6-8 characters): <input type='text' id='username' /><br />
13.Email: <input type='text' id='email' /><br />
14.<input type='submit' value='Check Form' /><br />
15.</form>
01.function formValidator(){
02.// Make quick references to our fields
03.var firstname = document.getElementById('firstname');
04.var addr = document.getElementById('addr');
05.var zip = document.getElementById('zip');
06.var state = document.getElementById('state');
07.var username = document.getElementById('username');
08.var email = document.getElementById('email');
09.
10.// Check each input in the order that it appears in the form!
11.if(isAlphabet(firstname, "Please enter only letters for your name")){
12.if(isAlphanumeric(addr, "Numbers and Letters Only for Address")){
13.if(isNumeric(zip, "Please enter a valid zip code")){
14.if(madeSelection(state, "Please Choose a State")){
15.if(lengthRestriction(username, 6, 8)){
16.if(emailValidator(email,"Please enter a valid email address")){
17.return true;
18.}
19.}
20.}
21.}
22.}
23.}
24.
25.
26.return false;
27.
28.}
  .'!-
 .'! e! & e t:
e t
!  eiee  . e& !"# !  Validator function " 7  F । ei a8  " a!!   .'! e
6d"  et"   + F ।
eiee e& яskp .:
001.<script type='text/javascript'>
002.
003.function formValidator(){
004.// Make quick references to our fields
005.var firstname = document.getElementById('firstname');
006.var addr = document.getElementById('addr');
007.var zip = document.getElementById('zip');
008.var state = document.getElementById('state');
009.var username = document.getElementById('username');
010.var email = document.getElementById('email');
011.
012.// Check each input in the order that it appears in the form!
013.if(isAlphabet(firstname, "Please enter only letters for your name")){
014.if(isAlphanumeric(addr, "Numbers and Letters Only for Address")){
015.if(isNumeric(zip, "Please enter a valid zip code")){
016.if(madeSelection(state, "Please Choose a State")){
017.if(lengthRestriction(username, 6, 8)){
018.if(emailValidator(email,"Please enter a valid email address")){
019.return true;
020.}
021.}
022.}
023.}
024.}
025.}
026.
027.
028.return false;
029.
030.}
031.
032.function notEmpty(elem, helperMsg){
033.if(elem.value.length == 0){
034.alert(helperMsg);
035.elem.focus(); // set the focus to this input
036.return false;
037.}
038.return true;
039.}
040.
041.function isNumeric(elem, helperMsg){
042.var numericExpression = /^[0-9]+$/;
043.if(elem.value.match(numericExpression)){
044.return true;
045.}else{
046.alert(helperMsg);
047.elem.focus();
048.return false;
049.}
050.}
051.
052.function isAlphabet(elem, helperMsg){
053.var alphaExp = /^[a-zA-Z]+$/;
054.if(elem.value.match(alphaExp)){
055.return true;
056.}else{
057.alert(helperMsg);
058.elem.focus();
059.return false;
060.}
061.}
062.
063.function isAlphanumeric(elem, helperMsg){
064.var alphaExp = /^[0-9a-zA-Z]+$/;
065.if(elem.value.match(alphaExp)){
066.return true;
067.}else{
068.alert(helperMsg);
069.elem.focus();
070.return false;
071.}
072.}
073.
074.function lengthRestriction(elem, min, max){
075.var uInput = elem.value;
076.if(uInput.length >= min && uInput.length <= max){
077.return true;
078.}else{
079.alert("Please enter between " +min+ " and " +max+ " characters");
080.elem.focus();
081.return false;
082.}
083.}
084.
085.function madeSelection(elem, helperMsg){
086.if(elem.value == "Please Choose"){
087.alert(helperMsg);
088.elem.focus();
089.return false;
090.}else{
091.return true;
092.}
093.}
094.
095.function emailValidator(elem, helperMsg){
096.var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
097.if(elem.value.match(emailExp)){
098.return true;
099.}else{
100.alert(helperMsg);
101.elem.focus();
102.return false;
103.}
104.}
105.</script>
106.
107.<form onsubmit='return formValidator()' >
108.First Name: <input type='text' id='firstname' /><br />
109.Address: <input type='text' id='addr' /><br />
110.Zip Code: <input type='text' id='zip' /><br />
111.State: <select id='state'>
112.<option>Please Choose</option>
113.<option>AL</option>
114.<option>CA</option>
115.<option>TX</option>
116.<option>WI</option>
117.</select><br />
118.Username(6-8 characters): <input type='text' id='username' /><br />
119.Email: <input type='text' id='email' /><br />
120.<input type='submit' value='Check Form' />
121.</form>

p'!:

First Name:
Address:
Zip Code:
State:
Username(6-8 characters):
Email:
Check Form

яskp sT[ E[\- ( JavaScr i pt St r i ng Funct i ons Tut or i al i n


Bangl a)

  : яo !#
  яo !#  

e
 6!  F 6# "!  ! + " 6 " & " p " яskp s + "6 '! 3 6!  'k   я a 6k
1 । e  ! + c яskp-e s i " e $#c property e& function(3  method o &  + ) &'; object ।

PSEUDO яskp 01:


01:
01.<script>

02.var myString = "Hello Thur!";

03.
04.//This is how you would access a property

05.var myProperty = myString.property;

06.

07.//This is how you would access a function

08.var myFunctionResult = myString.function(argument1, argument2);

09.</script>

sT[ 0p,R ?(


?( STRI NG PROPERTY)
String property + c 3 object m  F#   "1  । 3!: String object e lengthproperty F 3
String-e characters e  я  ।

sT[ E[\- ?


? ( STRI NG FUNCTI ON)
6! String m  a !F# 6 " String Function  a ! u6 7। 3!: 6! String Function e 8 
String 6 ! e& a !$#   n &k  ! 3 ! character $#  6!  & +  F!।
e
 $# t# 6#! &9 + c ei '!$# i " String  6 &" !  ! " & "  !"# ! String 
!  3 6! я  "
6 !।

STRING FUNCTIONS e$[ PROPERTI ES:


ei a8  ! + F  & 6! String  6  !,$d!,p"s6!, a.  e&   " 6 !। ei advanced
&9  6!  dynamic o & 6я " 7 k t !"# ! e я$ " d u n!   & ।
e +,- 
i ,a &- 
- '
& ,
&
$ &
p
&fяskpstring' &, E[\- r
+,- +
P\k
 
я a
,k /
। e  - '
~яskp-estring & e
g~propertye$[function(r
methodo $  ' )$\€object।

Pseudoяskp .:

<script type="text/javascript">
var myString = "Hello Thur!";

//This is how you would access a property


var myProperty = myString.property;

//This is how you would access a function


var myFunctionResult = myString.function(argument1, argument2);
</script>
String Property?
String property'
~ robject9m
R ia 0  &/f 0P । 0r-: String
objecte lengthproperty

i rString-echaracterse 9[%f я 
%।

String Function?

+,- String9m
R a
-ia 0,
&String Function a
- u, W। 0r-: +,-String Functione
nf
String0,
- e$[ a
-g
 %
?1 $k 
- 0r%
-characterg
 +,- 9 $ '


i-।
e grt,a-R $m '
~ ei E[\-g  &String0 , $&R- 
- &
$ &  -&a-String -R

r +,- я %
& ,
-।

String Functionse$[Properties:
ei anf
0P%
- '

i 
$ +,-String0 , 6 -, Vz-, p&s,-,  a1R e$[ 96R 
&
,
-। eiadvanced$m  +,-
dynamico
$ 0,я p& W 0k
t -&a- e яV
& d u
n6-

0P
$ ।

яskpString Length:

Advanced scripter0P p i я- p


я- ' 0rString 0- '
$। 0r- nr-
eя-webdeveloperesubmissionp& W 
 0r%
-usernamee яn ‡ˆ e
0$\character-nR -   ' -, E
& u6& '
$ $f$'  W
01 9$ 
&
an& 0P  +
Vstringe length 06 
0- ।
String Length Property:

length property charactere 9[%f


  R- 
rString-e

i।

яskp .:

<script type="text/javascript">
var myString = "123456";

var length = myString.length;

document.write("The string is this long: " + length);

// Same thing, but using the property inside the write function
document.write("<br />The string is this long: " + myString.length);

</script>

pP\R-:

String, $&R- '


Lengtho , $&R- '
$:
'
$:

Stringe ia character0rV   , rP +,-length property 0 E


n 0P-
&
$length property , $&R- '
$।
яskp .:

<script type="text/javascript">
var myString = "123456";
document.write("The string is this long: " + myString.length);

myString = myString + "7890";


document.write("<br />The string is now this long: " + myString.length);

</script>

pP\R-:

яskp sT[ 0 [/ $ pPxRf ( JavaScr i pt St r i ng Lengt h)


  : яo !#
  яo !#  

яskp sT[ 0 [/ $ pPxRf ( JAVASCRI PT STRI NG LENGTH)


LENGTH)
Advanced scripter  p i я! p я! + 3 String  ! + &। 3! 8 #! eя! o & .  6 e

submission  " 7   3 ! iuя ! e я! 20 ak e &' !8 !   + !,  " u" + &
&&+  7   .
 &
 " a!#"    $ s e length   ! ।

sT[ 0 [/ 0p,R ( STRI NG LENGTH PROPERTY)


PROPERTY)
length property  character e   
 !  3 s-e F।

01.<script>
02.var myString = "123456";
03.
04.var length = myString.length;
05.
06.document.write("The string is this long: " + length);
07.
08.// Same thing, but using the property inside the write function
09.document.write("<br />The string is this long: " + myString.length);
10.
11.</script>

p'!:
The string is this long: 6
The string is this long: 6The string is this long: 6
The string is this long: 6

sT[ , $&R- '


LENGTH o , $&R- '
$:
'
$:
s e F# character 3$   6 3 6! length property   n ! " & length property  6 &" !
+ &।
1.<script>
2.var myString = "123456";
3.document.write("The string is this long: " + myString.length);
4.
5.myString = myString + "7890";
6.document.write("<br />The string is now this long: " + myString.length);
7.
8.</script>
p'!:
The string is this long: 6
The string is now this long: 10The string is this long: 6
The string is now this long: 10

яskp sT[ ‹p E[\- ( JavaScr i pt Spl i t Funct i on)


  : яo !#
  яo !#  

s  &n
#   " &k   k" 3 a ! pg $# я 1!  । яskpo "  ।3 6! a ! m s
3!: "Bobby Susan Tracy Jack Phil Yannis" e& p " !       & я  " 6 !। 6!
space character " "  !  '  " 6 !। split function  !"# !
#   " 7  & 3 p"& s  k  ।

‹p E[\- 1 


1  ( SPLI T FUNCTI ON: DELI
DELI MI TER)
space character " "  + &   delimiter e& split function 3 s  &k  " e
 &&+  । p "
 e
 delimiter  k  3   !  '  F। e
 array " !"# ! e n " 7  । split function e p1 3#k
+ c delimiter ।

9n - ‹p E[\- e uP' -:


uP' -:
!   s e u+ !   + । s  &k + 3! e 5    । e ! 5 + c delimiter । k   &9
+ c split function  array  
 !  3  mySplitResult e я  " 6 ।
1.<script>
2.var myString = "123456789";
3.
4.var mySplitResult = myString.split("5");
5.
6.document.write("The first element is " + mySplitResult[0]);
7.document.write("<br /> The second element is " + mySplitResult[1]);
8.</script>

p'!:
The first element is 1234
The second element is 6789The first element is 1234
The second element is 6789
u6 u+ !   5  delimiter + & 6Fn  F। " & e
     ! ।  ! delimiter String + "
&"a" + । 6 &" character $#  n a' d  6:1 + ।

$ΠSPLI T FUNCTI ON e uP' -:


uP' -:
!    split function e u+ ! " 7  F 3 ! &d" + F 3  & ei '! s  split ।   'i! + "
 s " 7  F। ei u+ ! delimiter + c space character " " ।
01.<script>
02.var myString = "zero one two three four";
03.
04.var mySplitResult = myString.split(" ");
05.
06.for(i = 0; i < mySplitResult.length; i++){
07.document.write("<br /> Element " + i + " = " + mySplitResult[i]);
08.}
09.</script>

p'!:
Element 0 = zero
Element 1 = one
Element 2 = two
Element 3 = three
Element 4 = four
Element 0 = zero
Element 1 = one
Element 2 = two
Element 3 = three
Element 4 = four

яskp sT[ an9n- ( JavaScr i pt St r i ng Sear ch)


  : яo !#
  яo !#  

6! 3 a! i!   1  e& 3i iuя ! e ap"'" 'b an# k + F 3 6! ! я!$! i iuя ! " 7
  1  & " 1k " & 6! search function e 8  & # я &  iuя ! e ap"'" 'b$#   &
 " 6 !।

sT[ an9n- E[\-


E[\- ( JAVASCRI PT SEARCH
SEARCH FUNCTI ON)
ei s '! regular expression g+!  e& s  6 7k    3 " regular expression e  1 match
 F !। 3 match  " & e
 s e position 
!  &।  3 match !  " & -1 
!  &।

SEARCH FUNCTI ON REGULAR


REGULAR EXPRESSI ON:
e
  !  $# t# 6#! 3, 3! 6! regular expression " 7  &! "! e
 a&'i # slash e  8 1 &। ! 
u+ !   + ।
01.<script>
02.var myRegExp = /Alex/;
03.var string1 = "Today John went to the store and talked with Alex.";
04.var matchPos1 = string1.search(myRegExp);
05.
06.if(matchPos1 != -1)
07.document.write("There was a match at position " + matchPos1);
08.else
09.document.write("There was no match in the first string");
10.
11.
12.</script>

p'!:
There was a match at position 45There was a match at position 45
k  #!,   regular expression  F '#8# e
 ! "Alex" ।  search function  ei ! &&+ 
  F 3 string1 e e
 u6s" F !। e
 ' !  1 match  F    match e 6я'! (45) 
6 F।

sT[ an9n- E[\-


E[\- ( STRI NG SEARCH FUNCTI
FUNCTI ON: ALTERNATI VE SEARCHES)
regular expression e   &
# +  pipe character "|" । 3 8  Alternative 'b search  "
6 ! । e  
+  /RegExp1|RegExp2/ । '#8# t e
 'b search   6 & " 6! e! pipe character e
8  a ! $#  'b search  " 6 !।
01.<script>
02.var myRegExp = /Alex|John/;
03.var string1 = "Today John went to the store and talked with Alex.";
04.var matchPos1 = string1.search(myRegExp);
05.
06.if(matchPos1 != -1)
07.document.write("There was a match at position " + matchPos1);
08.else
09.document.write("There was no match in the first string");
10.
11.
12.</script>

p'!:
There was a match at position 6There was a match at position 6
k  #!   regular expression e # ! F: Alex e& John ।  search function  ei ! #
#я " &&+  F e&   F string1 e e$#  u6s" F !।

un&& an9n- E[\-


E[\- e uP' - ( ADVANCED SEARCH FUNCTI
FUNCTI ON)
!  u+ ! 8  6 s  & &I 3 & 3 search function   & я  ।
01.<script>
02.var myRegExp1 = /Tom|Jan|Alex/;
03.var string1 = "John went to the store and talked with Alexandra today.";
04.var matchPos1 = string1.search(myRegExp1);
05.
06.if(matchPos1 != -1)
07.document.write("The first string found a match at " + matchPos1);
08.else
09.document.write("No match was found in the first string");
10.
11.var myRegExp2 = /Tom|Jan|Alex /;
12.var string2 = "John went to the store and talked with Alexandra today.";
13.var matchPos2 = string2.search(myRegExp2);
14.if(matchPos2 != -1)
15.document.write("<br />The second string found a match at " + matchPos2);
16.else
17.document.write("<br />No match was found in the second string");
18.
19.var myRegExp3 = /Tom|Jan|Alexandra/;
20.var string3 = "John went to the store and talked with Alexandra today.";
21.var matchPos3 = string3.search(myRegExp3);
22.if(matchPos3 != -1)
23.document.write("<br />The third string found a match at " + matchPos3);
24.else
25.document.write("<br />No match was found in the third string");
26.
27.var myRegExp4 = /Tom|Jan|Alexandra/;
28.var string4 = "John went to the store and talked with Alex today.";
29.var matchPos4 = string4.search(myRegExp4);
30.if(matchPos4 != -1)
31.document.write("<br />The fourth string found a match at " + matchPos4);
32.else
33.document.write("<br />No match was found in the fourth string");
34.</script>

p'!:
The first string found a match at 39
No match was found in the second string
The third string found a match at 39
No match was found in the fourth stringThe first string found a match at 39
No match was found in the second string
The third string found a match at 39
No match was found in the fourth string

яskp sT[ 
p9 ( JavaScr i pt St r i ng Repl ace)
  : яo !#
  яo !#  

яskp s a& яk e e! k" F 3 8  6! s e " 3 ! 'b   p  " 6 !।  p ' !
+ 8 6! ei
ee  e 8  6! &&+  7 ! g+  " 6 !।
s  p '!:
'!
s  p '! e #i 8 ! 3#k F:
1.SearchFor: ! 'b  p + " 3 c। e
 + " 6 s &  $#  ek p'!।

2.ReplaceText: ! 'b   p   + &। e s e p я!।

 p '!  p: " 'b+ !"# ! s 


!  । 3 ! !"# ! 'b  p   ! + " & 6# "! s 
!  ।


p9 E[\-:
E[\-:sT[ 
p9
e!   s    & e& &&+  7 ! d  e
   p  &। p1 3#k + c      F e& d"7  + c
  p  " 3c।

01.<script>
02.var visitorName = "Chuck";
03.var myOldString = "Hello username! I hope you enjoy your stay username.";
04.var myNewString = myOldString.replace("username", visitorName);
05.
06.document.write("Old string = " + myOldString);
07.document.write("<br />New string = " + myNewString);
08.
09.</script>

p'!:
Old string = Hello username! I hope you enjoy your stay username.
New string = Hello Chuck! I hope you enjoy your stay username.Old
string = Hello username! I hope you enjoy your stay username.
New string = Hello Chuck! I hope you enjoy your stay username.
u6  3 c '#8# t p1 iuя ! 6 &" " + F। e
 + c SearchFor 3#k 7&d"।  $#  ek p'! &&+
8  ei  #  " 6 ।


p9 E[\-:
E[\-:0 g  ek
p\-
  s e 6 & "  $#  ek p'! &&+  &। e ! 61 + c '#8#  
' ! 6 & " s' &&+  &।
01.<script>
02.var visitorName = "Chuck";
03.var myOldString = "Hello username! I hope you enjoy your stay username.";
04.var myNewString = myOldString.replace(/username/, visitorName);
05.
06.document.write("Old string = " + myOldString);
07.document.write("<br />New string = " + myNewString);
08.
09.</script>
p'!:
Old string = Hello username! I hope you enjoy your stay username.
New string = Hello Chuck! I hope you enjoy your stay username.Old
string = Hello username! I hope you enjoy your stay username.
New string = Hello Chuck! I hope you enjoy your stay username.
n " 6 o  3 c & iuя ! 6 &" ! + !। $#  ek p'! e g& p6 8  ei  #   3 ।

p9 E[\-:
E[\-:0g$ 0 g  ek
p\-
 $#  ek p'! e ' 9 g i!6#
   g& ek p'! " 7  " 6 ।

01.<script>
02.var visitorName = "Chuck";
03.var myOldString = "Hello username! I hope you enjoy your stay username.";
04.var myNewString = myOldString.replace(/username/g, visitorName);
05.
06.document.write("Old string = " + myOldString);
07.document.write("<br />New string = " + myNewString);
08.
09.</script>
p'!:
Old string = Hello username! I hope you enjoy your stay username.
New string = Hello Chuck! I hope you enjoy your stay Chuck.Old string
= Hello username! I hope you enjoy your stay username.
New string = Hello Chuck! I hope you enjoy your stay Chuck.
3 + ' 9    + ।   !  " + & 3 3   e 'b  p  " i  k t s & 8 !  $# 
ek p'! &&+   u"।3 &  p  " i  k t g&  $#  ek p'! &&+   u"।

яskp sT[ i-
1kaE E[\- u
  ( JavaScr i pt i ndexOf Funct i on)
  : яo !#
  яo !#  

s '! indexOf e 8  6! 8 !   p я ! #i 8 ! 3#k '! 8  6 &!। p1 + c   
e& 6  + c a 

sT[ i-
1kaE E[\-:
E[\-:
i! .ka ' ! # 8 ! 3#k F। 3 d"7  + c ‚c।

1.SearchString:3 6!   "  c!।


2.Offset (‚c):

i! .ka '! u+ !:


u+ !
8 ! iu e s e www e 6я'! &  " 6 ।
1.<script>
2.var aURL = "http://www.tizag.com/";
3.var aPosition = aURL.indexOf("www");
4.
5.document.write("The position of www = " + aPosition);
6.</script>
p'!:
The position of www = 7The position of www = 7
i! .ka '! a 
u+ !:
u+ !
3   i! .ka '! &&+  p1 www e 6я'! &  " 6 "! p1 www  &n  6 www e
6я'! &  " 6 ।

01.<script>
02.var aURL = "http://www.tizag.com/www.html";
03.var aPosition = aURL.indexOf("www");
04.var secondPos = aURL.indexOf("www", aPosition + 1);
05.
06.document.write("The position of www = " + aPosition);
07.document.write("<br />The position of the second www = " + secondPos);
08.
09.</script>

p'!:

The position of www = 7

The position of the second www = 21The position of www = 7

The position of the second www = 21

яskp 0Ve
?$i+i1(
0Ve
?$i+i1( JavaScr i pt get El ement ByI d Tut or i al i n
Bangl a)

  : яo !#
  яo !#  

6!  !o яskp &&+    .'!  F!?


k
 l !  # 3i  " !  6 a F!?e
 +я
u6 8  eiee e n ! nt!  " 6 !।i. eŠ&u
e& $
e n&ii. ' ! 8  "  "
6 !।

яskp: .k n $
e n&ii. (document.getElementById)
яskp .k n.$
e n&ii.
01.<script>

02.function notEmpty(){

03.var myTextField = document.getElementById('myText');

04.if(myTextField.value != "")

05.alert("You entered: " + myTextField.value)

06.else

07.alert("Would you please enter some text?")

08.}

09.</script>

10.<input type='text' id='myText' />

11.<input type='button' onclick='notEmpty()' value='Form Checker' />

p'!:

document.getElementById  i
k
eiee e n e   n  
!  ।  ei
  n  myTextField !  & я  " 6 ।

$
e n&ii. &9 3  !    :
 
3! 6! getElementById function &&+  &! "! 6!  F# &9 n n !Y" +o  p я!। 6! 
a&'i  !  p я! 3 $
e n&ii. + c .k n a& яk e 6d" & '!।6! ei $
e n&ii. '!
&&+  " i 6!  a&'i eiee e n e i. eŠ&u
&&+  " + &।

яskp i- ei6ee (


ei6ee ( JavaScr i pt i nner HTML)

  : яo !#
  яo !#  

e
 &m  3    & eiee !
n  6 &" !  " 6 &! i! eiee e 8    
k
 6 &" !
 " 6 ।
i! eiee (innerHTML) e 8  
k
6 &" !:
!
p " eiee e n e i! eiee p6 F 3 eiee . e& 
k
u  !  '  3  o 6! e&
kя
 $  8 6o  3 ।e  n i! eiee p6 6 &" !  9d7 o & 6я " 7   3 ।

i! eiee p6  +я & &&+  " i F# ps" p я!। p1  e n e i.  " + & " 6
"  getElementById function e 8  6  !  " + &।
1.<script>

2.function changeText(){

3.document.getElementById('boldStuff').innerHTML = 'Fred Flinstone';

4.}

5.</script>

6.<p>Welcome to the site <b id='boldStuff'>dude</b> </p>

7.<input type='button' onclick='changeText()' value='Change Text'/>

p'!
Welcome to the site dude
3 +   я!   & eiee e n e 
k
 6 &" !   3 ।n   e!o я!!  & &&+  7
  
k
 6 k   eiee 
k
 6 &" !  " 6 &। !  e  !   + ।

iuя i-,a
 u, t
t 
0k
 , $&R
, $&R-:
01.<script>

02.function changeText2(){

03.var userInput = document.getElementById('userInput').value;

04.document.getElementById('boldStuff2').innerHTML = userInput;

05.}

06.</script>

07.<p>Welcome to the site <b id='boldStuff2'>dude</b> </p>

08.<input type='text' id='userInput' value='Enter Text Here' />

09.<input type='button' onclick='changeText2()' value='Change Text'/>


p'!
Welcome to the site dude
Enter Text

i! eiee (innerHTML) e +" eiee e 6 &" !:


6! e  n  8 eiee i!
  " 6 !।   
k
  o 6 &" !  " 6 ।

01.<script>

02.function changeText3(){

03.var oldHTML = document.getElementById('para').innerHTML;

04.var newHTML = "<span style='color:#ffffff'>" + oldHTML +"</span>";

05.document.getElementById('para').innerHTML = newHTML;

06.}

07.</script>

08.<p id='para'>Welcome to the site <b id='boldStuff3'>dude</b> </p>

09.<input type='button' onclick='changeText3()' value='Change Text'/>

p'!
Welcome to the site dude

You might also like