SitePoint Sponsor

User Tag List

Results 1 to 19 of 19
  1. #1
    SitePoint Guru
    Join Date
    Dec 2008
    Posts
    692
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    geting nulll value

    have a function in which i have
    document.getElementById('yn').value='Y'
    alert(document.getElementById('yn').value)
    but still get get null value

  2. #2
    SitePoint Evangelist Dave Morton's Avatar
    Join Date
    Sep 2003
    Location
    Carson City, NV
    Posts
    557
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try:
    Code:
    var yn = document.getElementById('yn');
    yn.value = "y";
    alert(yn.value)
    Making a difference, one little psychotic episode at a time
    Geek Cave Creations
    Beta testers needed for pChat
    Dave's Gallery

  3. #3
    SitePoint Guru
    Join Date
    Dec 2008
    Posts
    692
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Microsoft JScript runtime error: 'null' is null or not an object

    i getthis error

  4. #4
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sounds like there is no element with id="yn". Note that ID attributes are case-sensitive, and make sure you're not running the script before the element is created (e.g., using a script in the <head> of the document).
    Birnam wood is come to Dunsinane

  5. #5
    SitePoint Guru
    Join Date
    Dec 2008
    Posts
    692
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hidden element yn exixts and is in small case

  6. #6
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this, then:
    Code JavaScript:
    var yn = document.getElementById("yn");
    alert(typeof yn);

    Does it say 'object'? Then we need more info.

    Does it say 'null'? Then you're running the script before the element has been created.
    Birnam wood is come to Dunsinane

  7. #7
    SitePoint Evangelist Dave Morton's Avatar
    Join Date
    Sep 2003
    Location
    Carson City, NV
    Posts
    557
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also try:
    Code:
    window.onload = function() {
      var yn = document.getElementById("yn");
      yn.value = "y";
      alert(yn.value);
    }
    didn't I mention going to bed? I'm an idiot.
    Making a difference, one little psychotic episode at a time
    Geek Cave Creations
    Beta testers needed for pChat
    Dave's Gallery

  8. #8
    SitePoint Guru
    Join Date
    Dec 2008
    Posts
    692
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    in alert i get object
    i get yhe script error fro anull at line

    var yn = document.getElementById('yn');

  9. #9
    SitePoint Evangelist Dave Morton's Avatar
    Join Date
    Sep 2003
    Location
    Carson City, NV
    Posts
    557
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Interesting. Gonna have to sleep on it.
    Making a difference, one little psychotic episode at a time
    Geek Cave Creations
    Beta testers needed for pChat
    Dave's Gallery

  10. #10
    SitePoint Guru
    Join Date
    Dec 2008
    Posts
    692
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    any valid replies

  11. #11
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by svibuk View Post
    any valid replies
    Perhaps if you try posting in English ...

    Quote Originally Posted by svibuk View Post
    i get yhe script error fro anull at line
    What, exactly does that mean? If you expect us to spend time and effort helping you, at least you could show us the courtesy of checking your spelling before posting.

    If it means what I think it does, the only explanation is that document is undefined, which either means you're using a very odd browser or there's something you're not telling us.

    Quote Originally Posted by svibuk View Post
    in alert i get object
    Quote Originally Posted by AutisticCuckoo View Post
    Does it say 'object'? Then we need more info.
    What does the markup look like where you create this element?
    Where is the script in relation to that markup?
    Birnam wood is come to Dunsinane

  12. #12
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    Does your code look like this?

    Code html4strict:
    <head>
    <script type="text/javascript">
    function someFunction() {
        document.getElementById('yn').value='Y'
        alert(document.getElementById('yn').value);
    }
    </script>
    </head>
    <body>
    <form>
    ...
    </form>
    </body>

    Or more like this?

    Code html4strict:
    <head>
    </head>
    <body>
    <form>
    ...
    </form>
    <script type="text/javascript">
    function someFunction() {
        document.getElementById('yn').value='Y'
        alert(document.getElementById('yn').value);
    }
    </script>
    </body>
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  13. #13
    SitePoint Guru
    Join Date
    Dec 2008
    Posts
    692
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i had dne both of them
    but both giving me the error
    at presnt its after </form>

  14. #14
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    You will find that the following works:

    Code html4strict:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html lang="en"> 
    <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <title>Form with hidden value</title>
    </head> 
     
    <body> 
    <form>
        <p>
            <input type="hidden" id="yn" name="yn">
            <input type="submit" value="Form with hidden value">
        </p>
    </form>
    <script type="text/javascript">
    var yn = document.getElementById("yn");
    yn.value = "y";
    alert(yn.value);
    </script>
    </body> 
    </html>

    How does yours differ?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  15. #15
    SitePoint Guru
    Join Date
    Dec 2008
    Posts
    692
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    </form>

    <script type="text/javascript"language="javascript">

    function Check()
    {

    var delconfirm = confirm('Are you sure ? You want to delete Details ?')
    if (delconfirm == true)
    {

    var yn = document.getElementById('yn');
    yn.value = "Y";

    // document.getElementById('yn').value='Y'
    alert(document.getElementById('yn').value)
    return true
    }
    else
    {

    var yn = document.getElementById('yn');
    yn.value = "N";
    alert(document.getElementById('yn').value)
    return false
    }
    }


    </script>

    <input id="yn" name="yn" type="hidden" runat="server" />


    Microsoft JScript runtime error: 'null' is null or not an object
    this is wht i have

  16. #16
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    The script is above the "yn" identifier, ergo - the "yn" identifier does not exist.

    When the script is below the "yn" identifier the script will be able to find it and work with it.

    Advice: Place the script just before the </body> tag.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  17. #17
    SitePoint Guru
    Join Date
    Dec 2008
    Posts
    692
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i am sorry i made a mstake in placing it here in forums
    in my page its
    first the element "yn"
    then
    </form>
    then the <script>
    </body>

    its in correct sequence

  18. #18
    SitePoint Guru
    Join Date
    Dec 2008
    Posts
    692
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks a lot
    it was the elelemt placing prblm
    i shifted them in order its wrking now

    thanks once again for the finding the error

  19. #19
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    You're welcome.

    head->pillow
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

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