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 5 of 5
  1. #1
    New to the CF scene
    Join Date
    May 2012
    Location
    Mumbai
    Posts
    9
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Smile How to assign textbox input values to variable in javascript

    [Solved]
    Hi!

    I am quite new to the world of JavaScript as I have done basic corse for it...
    and I have learnt that best way to understand it is to play around with it...
    but now I am stuck with on of the problem!!

    Problem: How can we assign text box input values by user to a variable and display that variable back on another element of the same HTML document(dynamically)...

    Conditions:
    • The value has to be stored as a JavaScript variable only.

      No server-side script is to be used and has to be done locally.


    Please help!

    [Solved]
    Last edited by Webtech; 05-12-2012 at 07:58 PM. Reason: Solved

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,150
    Thanks
    203
    Thanked 2,547 Times in 2,525 Posts
    This is extremly basic and fundamental. Are you sure that you paid attention to your course? And is this homework? If so have a look at forum rule 1.5.


    Code:
    <script type = "text/javascript">
    function doIt(val) {
    document.getElementById("theResult").innerHTML = val;
    }
    </script>
    
    <input type = "text" id = "txt" onblur = "doIt(this.value)">
    <br><br>
    <span id = "theResult"></span>
    Magistrates will act on indecent shows. - Headline in Surrey Advertiser

    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:

    Webtech (05-12-2012)

  • #3
    New to the CF scene
    Join Date
    May 2012
    Location
    Mumbai
    Posts
    9
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Smile

    Quote Originally Posted by Philip M View Post
    This is extremly basic and fundamental. Are you sure that you paid attention to your course? And is this homework? If so have a look at forum rule 1.5.


    Code:
    <script type = "text/javascript">
    function doIt(val) {
    document.getElementById("theResult").innerHTML = val;
    }
    </script>
    
    <input type = "text" id = "txt" onblur = "doIt(this.value)">
    <br><br>
    <span id = "theResult"></span>
    Magistrates will act on indecent shows. - Headline in Surrey Advertiser
    Yes I did pay attention but have not practiced after it!...and I read the forum rule 1.5 and I am sorry for not doing homework correctly

    please can you suggest me where I can post my silly questions or JavaScript short code snippets for study purpose and better understanding...

    @Philip M: Thank you very much for clearing my doubt ...

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,150
    Thanks
    203
    Thanked 2,547 Times in 2,525 Posts
    Quote Originally Posted by Webtech View Post
    please can you suggest me where I can post my silly questions or JavaScript short code snippets for study purpose and better understanding...
    You are welcome to post your questions here but, as a general rule, the people helping out in this forum don't write code for others (especially code that appears to be for homework), but try to help with fixing code that doesn't work. You may perhaps get someone to write a script for you, but you'll be far more likely to get help if you have made a substantial effort and written some code yourself. Then someone here will almost certainly help you correct/improve your work.

    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:

    Webtech (05-12-2012)

  • #5
    New to the CF scene
    Join Date
    May 2012
    Location
    Mumbai
    Posts
    9
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Smile

    Quote Originally Posted by Philip M View Post
    You are welcome to post your questions here but, as a general rule, the people helping out in this forum don't write code for others (especially code that appears to be for homework), but try to help with fixing code that doesn't work. You may perhaps get someone to write a script for you, but you'll be far more likely to get help if you have made a substantial effort and written some code yourself. Then someone here will almost certainly help you correct/improve your work.
    Thank you for the advice for my further learning process...

    Thank you again


  •  

    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
    •