Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Banned
    Join Date
    Jan 2007
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Problems with getElementByID

    I have made a system to add names to a list. I have 3 input text fields, and I gave them all a unique ID. But I can't manage to reach them with getElementByID. Could someone look into my code and tell me what I am doing wrong?

    //this is the part were I made the input fields and there ID's//

    <input type="Text" id="input" />
    <input type="Text" id="search" />
    <input type="Text" id="result" onFocus="blur()" />
    --------------------------------------------------------------------
    //this is were I use the getElent to reach the textfields by ID//

    var inputField = document.getElementById('input');
    var searchField = document.getElementById('search');
    var resultField = document.getElementById('result');
    --------------------------------------------------------------------
    //this is how i've put it in the code//

    function addName() {
    if (inputField.value != '') {
    namen.push(inputField.value);
    }
    } //addName

    function searchArray() {
    gevonden = 'nee';
    for (j = 0; gevonden == 'nee' && j < namen.length; j++) {
    if (namen[j] == searchField.value) {
    gevonden = 'ja';
    resultField.value = j;
    }
    else {
    resultField.value = 'niet gevonden';
    }
    }
    }

    -----------------------------------------------------------------------

    Thank you in advance!

    Donny

  • #2
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,963
    Thanks
    120
    Thanked 76 Times in 76 Posts
    before this line:

    namen.push(inputField.value);

    put

    alert(inputField);

    does it show [object] or something like that, if it does then the problem is .value . Specify the error returned next time.

    Regards.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •