Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. JavaScript
  4. Javascript validate the master and content page

Javascript validate the master and content page

Scheduled Pinned Locked Moved JavaScript
javascripttutorial
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sathyan_8294
    wrote on last edited by
    #1

    hai all
    i want to validate the content page using javascript external file.
    i keep 5 text box in content page.i want to validate the textbox like
    fields must not blank,
    characters only allowed for name,state,country.
    numbers only allowed for age,pincode
    email validation etc.
    i want to validate the textboxes in content page using javascript external file.
    how to do these...plz send javascript code...thanks in advance...

    D M 2 Replies Last reply
    0
    • S sathyan_8294

      hai all
      i want to validate the content page using javascript external file.
      i keep 5 text box in content page.i want to validate the textbox like
      fields must not blank,
      characters only allowed for name,state,country.
      numbers only allowed for age,pincode
      email validation etc.
      i want to validate the textboxes in content page using javascript external file.
      how to do these...plz send javascript code...thanks in advance...

      D Offline
      D Offline
      DaveAuld
      wrote on last edited by
      #2

      Firstly, Why did you put your question in a code block, doesn't look very clever............ Ok, so back to your question; You can use the object onChange to call a javascript function to validate the content as each element changes. You could also use a button when you submit to check each element. The code below is a sample to help you get going, but there are heaps of examples on the net. You could take all the javascript out of the lower script block and place it in a reference file as shown in the upper script block entry

      <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
      <title></title>

      <script type="text/javascript" src="js/thejsfile.js"></script>
      

      </head>
      <body>

      <table>
          <tr><td>Name:</td><td><input id="textName" type="text" onchange="validateName()"/></td><td id="nameValidMessage"></td></tr>
          <tr><td>Age:</td><td><input id="textAge" type="text" onchange="validateAge()"/></td><td id="ageValidMessage"></td></tr>
      </table>
      <input id="ButtonGo" type="button" value="Go" onclick="go\_click()"/>
      <script type="text/javascript">
      
          function validateAge() {
              var valid = false
              //write you code to validate the age
              //set valid to true if all ok
      
              if (textAge.value == "99") { valid = true; }
      
              //update the page message
              if (!valid) {
                  ageValidMessage.innerHTML = "Invalid Age";
              }
              else {
                  ageValidMessage.innerHTML = "";
              }
      
              return valid
          }
      
          function validateName() {
              var valid = false
              //write you code to validate the name
              //set valid to true if all ok
      
              if (textName.value == "Dave") { valid = true; }
      
              //update the page message
              if (!valid) {
                  nameValidMessage.innerHTML = "Invalid Name";
              }
              else {
                  nameValidMessage.innerHTML = "";
              }
      
              return valid
          }
      
          function go\_click() {
              var valid
      
      1 Reply Last reply
      0
      • S sathyan_8294

        hai all
        i want to validate the content page using javascript external file.
        i keep 5 text box in content page.i want to validate the textbox like
        fields must not blank,
        characters only allowed for name,state,country.
        numbers only allowed for age,pincode
        email validation etc.
        i want to validate the textboxes in content page using javascript external file.
        how to do these...plz send javascript code...thanks in advance...

        M Offline
        M Offline
        MalarGayu
        wrote on last edited by
        #3

        hi i just wanted to know whether u got a solution for your question because i am facing the same problem now but still did not get any solution for it....i need to use javascript to validate a textbox placed in content page so can u plz help me in this issue....i am not able to get the id of the textbox.... K.Gayathri

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups