Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
BOOK: Professional Ajax ISBN: 978-0-471-77778-6
This is the forum to discuss the Wrox book Professional Ajax by Nicholas C. Zakas, Jeremy McPeak, Joe Fawcett; ISBN: 9780471777786
Important: For the new 2nd edition of this book, please post here instead: [url="http://p2p.wrox.com/forum.asp?FORUM_ID=307"]http://p2p.wrox.com/forum.asp?FORUM_ID=307[/url]
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional Ajax ISBN: 978-0-471-77778-6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 29th, 2006, 08:42 AM
Registered User
 
Join Date: Nov 2006
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Need help with Chapter 4

Thanks with the book. Is a really great book ;)
But i have a problem with "IncrementalFieldValidation.js"

With this code you can controll only one textfield.
But what is when i have 2 textfields with two Buttons?
////// Test ////// Buttton (disabled)
///// Alex /////// Button (available)

The problem is with the code from "IncrementalFieldValidation.js" controll both txtfields and buttons :( This means when i type a correct string into one textfield then both buttons are available. What must i change?
Code of IncrementalFieldValidation.js:
//Ajax
var oXmlHttp = null;
var iTimeoutId = null;

//function to validate fields
function validateField(oEvent) {
    oEvent = oEvent || window.event;
    var txtField = oEvent.target || oEvent.srcElement;

    var btnNextTest = document.getElementById("btnNextTest");
    var btnNextTest1 = document.getElementById("btnNextTest1");;

    btnNextTest.disabled = true;
    btnNextTest1.disabled = true;

    if (iTimeoutId != null) {
        clearTimeout(iTimeoutId);
        iTimeoutId = null;
    }

    if (!oXmlHttp) {
        oXmlHttp = zXmlHttp.createRequest();
    } else if (oXmlHttp.readyState != 0) {
        oXmlHttp.abort();
    }

    oXmlHttp.open("get", "includes/checkingForm.php?" + txtField.name + "=" + encodeURIComponent(txtField.value), true);
    oXmlHttp.onreadystatechange = function () {

        if (oXmlHttp.readyState == 4) {
            if (oXmlHttp.status == 200) {
                var arrInfo = oXmlHttp.responseText.split("||");
                var imgError = document.getElementById("img" + txtField.id.substring(3) + "Error");

                if (!eval(arrInfo[0])) {
                    imgError.title = arrInfo[1];
                    imgError.style.display = "";
                    txtField.valid = false;
                } else {
                    imgError.style.display = "none";
                    txtField.valid = true;
                }

                btnNextTest.disabled = !txtField.valid;
                btnNextTest1.disabled = !txtField.valid;

            } else {
                alert("An error occurred while trying to contact the server.");
            }
        }
    };

    iTimeoutId = setTimeout(function () {
        oXmlHttp.send(null);
    }, 500);
};[/code]

and the onload file:
Code:
window.onload = function () {
    if (zXmlHttp.isSupported()) {
        var btnNextTest = document.getElementById("btnNextS");    
        var btnNextTest1 = document.getElementById("btnNextSp");

        var txtTest = document.getElementById("txtTest");
        var txtTest1 = document.getElementById("txtTest1");

        btnNextTest.disabled = true;
        btnNextTest1.disabled = true;

        txtTest.onkeyup = validateField;
        txtTest.onchange = validateField;
        txtTest1.onkeyup = validateField;
        txtTest1.onchange = validateField;

        txtTest.valid = false;   
        txtTest1.valid = false;       

    }
};
Hope this is the correct forum and you can help me

Greetings
Berliner








Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 2 - End of chapter exercises whizzkid1892 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 1 July 30th, 2008 12:02 PM
chapter 7 - chapter 11 pelopito BOOK: Beginning CSS: Cascading Style Sheets for Web Design ISBN: 978-0-7645-7642-3 3 January 6th, 2008 11:40 AM
Generics chapter 12 difficult chapter i found ...? Larryz C# 2005 1 July 4th, 2007 09:40 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.