• Save
Javascript ch7
Upcoming SlideShare
Loading in...5
×
 

Javascript ch7

on

  • 317 views

 

Statistics

Views

Total Views
317
Views on SlideShare
217
Embed Views
100

Actions

Likes
0
Downloads
0
Comments
0

3 Embeds 100

http://bradyisstudying.blogspot.tw 92
http://bradyisstudying.blogspot.com 7
http://bradyisstudying.blogspot.kr 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Javascript ch7 Javascript ch7 Presentation Transcript

    • HFJS – BookReview Ch7Brady Cheng
    • Agenda What is Form? How to Get Its Value? Events Invoked by Form Warning for Empty Input Warning for NaN Warning for Specific Patterns
    • Form We want to verify a form and its inputs, i.e.
    • Get value Method1  <inputid="msgId" name=“msgName" type="text“/>  Use getElementById(“msgId”); Method2  Use form object  <input id="msgId" name=“msgName" type="text“ onclick=“verifyFunc(this.form);”/> function verifyFunc(theForm) { var value = theForm[“msgName”].value ; } property
    • Events onchange onfocus & onblur select input leave onblur
    • Empty Input In HTML <div class = "field"> Enter something: <input id="id1" name="name1" size="40" onblur="isEmpty( this, document.getElementById(spanId1));" /> <span id="spanId1" class="help"> </span> </div> In JS function isEmpty(form, helpText){ if(form.value.length == 0){ same if(helpText != null){ helpText.innerHTML = "NULL"; } } return; }
    • NaN(Not a Number) Use isNaN() build-in function if( isNaN(form.value) ) { alert(“this is not a number”); }
    • Specific Patterns We can use Regular expressions to match/filter the wanted patterns However, I want to skip this part until I start to doc the Perl introduction!  var regex = /some regex/; if( regex.test(form.value)) { //do something when matched } else { //do something when mismatched }