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 6 of 6
  1. #1
    Regular Coder
    Join Date
    Jan 2006
    Posts
    251
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question [object HTMLInputElement]

    Attempting to pass the value of a Javascript variable to a PHP variable.
    The input field named MajorEdit3 does dynamically load a value based upon the user's listbox selection. It is that value which needs to be passed to the PHP variable.
    The receiving page keeps returning the following:

    [object HTMLInputElement]

    So it recognizes there is data but it's failing to completely handle the request.
    Anyone see what I'm missing here?

    Sending page:
    Code:
    <input type="text" name="MajorEdit3" id="MajorEdit3" size="3">
    <script>
    	var MajorRecords = document.getElementById("MajorEdit3");
    document.write("<a href=\"DBEditMajor.php?record="+MajorRecords+"\"><input disabled type='submit' value='Save revisions' name='MajorRev' id='MajorRev' title='Store Major revisions' resolveData()></a>");
    </script>
    Code:
    <?php
    session_start();
    echo $_GET['record'];
    ?>

  • #2
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    the getElementById function, surprisingly enough, returns an element, not a value.
    add .value to the end to get the value...

  • #3
    Regular Coder
    Join Date
    Mar 2005
    Location
    D0u$h!t3 k4?
    Posts
    512
    Thanks
    2
    Thanked 5 Times in 5 Posts
    Quote Originally Posted by GJay View Post
    the getElementById function, surprisingly enough, returns an element, not a value.
    add .value to the end to get the value...
    Actually, it gets a DOM representation, an "object" (Document Object Model) of the element. The actual element name is stored in document.getElementById("MajorEdit3").nodeName

    It could also be stored in tagName, name and localName (Firefox has so many ways to show it). nodeName should work in almost any browser that supports DOM scripting. AFAIK, IE6, Fx and Opera do support it.
    PHP Code:
    $hello file_get_contents('hello.txt'); echo $hello
    hello

  • #4
    Regular Coder
    Join Date
    Jan 2006
    Posts
    251
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    Adjusted the code to

    var MajorRecords = document.getElementById("MajorEdit3").nodeName;

    Now I'm getting "INPUT" instead of "[object HTMLInputElement]".



    What I'm trying to collect is the contents of the following input box:
    <input type="text" name="MajorEdit3" id="MajorEdit3" size="3">

  • #5
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    It seems rpgfan has managed to confuse you.
    document.getElemenyByID('something');

    returns the element with id 'something'.

    suffixing '.nodeName', as it would suggest, returns the name of the node that is the element, in your case 'input'.

    suffixing '.value' instead, again unsurprisingly, returns the 'value' attribute of the element; that is (for an input), whatever is present in the field.

  • #6
    Regular Coder
    Join Date
    Jan 2006
    Posts
    251
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    GJay,

    Swapped nodeName for nodeValue.

    Now I'm seeing accurate info in the status bar.

    DBEditMajor.php?position=null
    Working to get the current field value to replace "null".
    Thanks


  •  

    Posting Permissions

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