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
    New to the CF scene
    Join Date
    Apr 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Setting value of Button with DOM

    I am trying to set the value of a regular form input button using the Document Object Model (DOM), however, I am not able to do so in fcirefox, the following code does not work in Firefox but works fine in Internet Explorer.

    Please provide some input

    <!--- Javascript here --->
    function SetValue() {
    document.getElmentById("OneButton").value = "New Value";
    }

    <!-- html here --->
    <form method="post">
    <input type="button" name="OneButton" id="OneButton" value="First Value" onclick="SetValue();">
    </form>
    Last edited by Mike777077; 04-17-2009 at 06:59 PM.

  • #2
    bdl
    bdl is offline
    Regular Coder
    Join Date
    Apr 2007
    Location
    Camarillo, CA US
    Posts
    590
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Note that the method is getElementById, not getElmentById.

    Also, do you have the JavaScript in your markup body (i.e you're using HTML comment tags) instead of inside a SCRIPT tag?

    Two other things to consider: you should make sure that the DOM functions are set after the document loads, i.e. using a window.onload event handler, or pushing the JS code down below the markup at the bottom of the body tag. The other thing is, you should probably reference the 'value' attribute with element.setAttribute("value","whatever"), e.g.
    Code:
    <!-- html here --->
    <form method="post">
    <input type="button" name="OneButton" id="OneButton" value="First Value" onclick="SetValue();">
    </form>
    
    <script>
    function SetValue() {
      document.getElementById("OneButton").setAttribute("value","New Value");
      return false;
    }
    </script>


  •  

    Posting Permissions

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