Click here to Skip to main content
15,887,428 members
Home / Discussions / JavaScript
   

JavaScript

 
QuestionIssue w/ Javascript inside 64 bit browser Pin
bgates197026-Oct-11 5:26
bgates197026-Oct-11 5:26 
AnswerRe: Issue w/ Javascript inside 64 bit browser Pin
Dennis E White27-Oct-11 9:08
professionalDennis E White27-Oct-11 9:08 
AnswerRe: Issue w/ Javascript inside 64 bit browser Pin
jsc4228-Oct-11 1:38
professionaljsc4228-Oct-11 1:38 
QuestionHTMLInput.name Pin
Ali Al Omairi(Abu AlHassan)25-Oct-11 21:40
professionalAli Al Omairi(Abu AlHassan)25-Oct-11 21:40 
AnswerRe: HTMLInput.name Pin
Gerben Jongerius25-Oct-11 22:10
Gerben Jongerius25-Oct-11 22:10 
GeneralRe: HTMLInput.name Pin
Ali Al Omairi(Abu AlHassan)25-Oct-11 23:41
professionalAli Al Omairi(Abu AlHassan)25-Oct-11 23:41 
QuestionJavascript validate the master and content page Pin
sathyan_829423-Oct-11 2:45
sathyan_829423-Oct-11 2:45 
AnswerRe: Javascript validate the master and content page Pin
DaveAuld23-Oct-11 3:41
professionalDaveAuld23-Oct-11 3:41 
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

XML
<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 = false
            //Do a validation of Name and Age
            valid = validateName() && validateAge()

            if (valid) {
                //Do what you need to if all ok
            }

        }
    </script>
</body>
</html>

Dave
Find Me On: Web|Facebook|Twitter|LinkedIn

Folding Stats: Team CodeProject


AnswerRe: Javascript validate the master and content page Pin
MalarGayu9-Nov-11 15:33
MalarGayu9-Nov-11 15:33 
QuestionWhere is the data behind the page? Pin
LeonardoDaga22-Oct-11 0:37
LeonardoDaga22-Oct-11 0:37 
AnswerRe: Where is the data behind the page? Pin
Richard MacCutchan22-Oct-11 1:48
mveRichard MacCutchan22-Oct-11 1:48 
GeneralRe: Where is the data behind the page? Pin
LeonardoDaga22-Oct-11 6:12
LeonardoDaga22-Oct-11 6:12 
GeneralRe: Where is the data behind the page? Pin
Richard MacCutchan22-Oct-11 6:26
mveRichard MacCutchan22-Oct-11 6:26 
GeneralRe: Where is the data behind the page? Pin
DaveAuld22-Oct-11 8:21
professionalDaveAuld22-Oct-11 8:21 
GeneralRe: Where is the data behind the page? Pin
Richard MacCutchan22-Oct-11 21:51
mveRichard MacCutchan22-Oct-11 21:51 
GeneralRe: Where is the data behind the page? Pin
DaveAuld22-Oct-11 21:59
professionalDaveAuld22-Oct-11 21:59 
GeneralRe: Where is the data behind the page? Pin
Richard MacCutchan23-Oct-11 2:17
mveRichard MacCutchan23-Oct-11 2:17 
GeneralRe: Where is the data behind the page? Pin
DaveAuld24-Oct-11 4:50
professionalDaveAuld24-Oct-11 4:50 
GeneralRe: Where is the data behind the page? Pin
Richard MacCutchan24-Oct-11 5:16
mveRichard MacCutchan24-Oct-11 5:16 
GeneralRe: Where is the data behind the page? Pin
AspDotNetDev23-Oct-11 8:24
protectorAspDotNetDev23-Oct-11 8:24 
GeneralRe: Where is the data behind the page? Pin
DaveAuld23-Oct-11 8:31
professionalDaveAuld23-Oct-11 8:31 
GeneralRe: Where is the data behind the page? Pin
DaveAuld24-Oct-11 4:51
professionalDaveAuld24-Oct-11 4:51 
GeneralRe: Where is the data behind the page? Pin
LeonardoDaga31-Oct-11 0:36
LeonardoDaga31-Oct-11 0:36 
QuestionUncaught SyntaxError: Unexpected token ILLEGAL Pin
Vimalsoft(Pty) Ltd19-Oct-11 22:02
professionalVimalsoft(Pty) Ltd19-Oct-11 22:02 
AnswerRe: Uncaught SyntaxError: Unexpected token ILLEGAL Pin
Richard Andrew x6422-Oct-11 12:18
professionalRichard Andrew x6422-Oct-11 12:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.