Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-12-2012, 06:09 PM   PM User | #1
Webtech
New to the CF scene

 
Join Date: May 2012
Location: Mumbai
Posts: 9
Thanks: 4
Thanked 0 Times in 0 Posts
Webtech is an unknown quantity at this point
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
Webtech is offline   Reply With Quote
Old 05-12-2012, 06:54 PM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,044
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
Philip M is offline   Reply With Quote
Users who have thanked Philip M for this post:
Webtech (05-12-2012)
Old 05-12-2012, 07:25 PM   PM User | #3
Webtech
New to the CF scene

 
Join Date: May 2012
Location: Mumbai
Posts: 9
Thanks: 4
Thanked 0 Times in 0 Posts
Webtech is an unknown quantity at this point
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 ...
Webtech is offline   Reply With Quote
Old 05-12-2012, 07:31 PM   PM User | #4
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,044
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
Philip M is offline   Reply With Quote
Users who have thanked Philip M for this post:
Webtech (05-12-2012)
Old 05-12-2012, 07:48 PM   PM User | #5
Webtech
New to the CF scene

 
Join Date: May 2012
Location: Mumbai
Posts: 9
Thanks: 4
Thanked 0 Times in 0 Posts
Webtech is an unknown quantity at this point
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
Webtech is offline   Reply With Quote
Reply

Bookmarks

Tags
assign, input, textbox, values, variable

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:39 AM.


Advertisement
Log in to turn off these ads.