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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts

    javascript get value of input field

    I'm new in web-development. I've searched it but it's not found. I make a input then how i get value of it for javascript value?
    Last edited by jonjo; 07-23-2011 at 12:54 PM.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,081
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    This is pretty fundamenatal and ought to be covered in any textbook. Assuming that your input is a textbox:-

    Code:
    <input type = "text" id = "txt1">
    <br>
    <input type = "button" value = "Click to get value entered into textbox" onclick = "getValue()">
    
    <script type = "text/javascript">
    function getValue() {
    var val = document.getElementById("txt1").value;
    alert (val);
    }
    
    </script>
    The function can of course be called in different ways.


    All this talk about ripping people's heads off - that going below the belt, really. - Presenter, BBC Radio 5 Live

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • Users who have thanked Philip M for this post:

    jonjo (07-23-2011)

  • #3
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts
    sure, Is ".value" used for only numbers?

  • #4
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,981
    Thanks
    56
    Thanked 557 Times in 554 Posts
    Quote Originally Posted by jonjo
    sure, Is ".value" used for only numbers?
    it probably took you twice as long to type that question as it would have to test it yourself


  •  

    Tags for this Thread

    Posting Permissions

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