Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
What am I doing wrong here? (assigning variable through <input> button)
Old 03-02-2010, 11:02 AM What am I doing wrong here? (assigning variable through <input> button)
Junior Talker

Posts: 1
Name: Brett Sprouse
Trades: 0
This should be a simple question, the problem is I just have alot of holes in my knowledge so I'm not sure what I should be looking for. I've looked through some reference guides trying to find out what I'm missing, but realizing I wasn't too sure what to look for I figured I'd post here. Sorry if it's a dumb question.

So I know XHTML, CSS, Python, and am currently in the midst of learning javascript. I was fooling around trying to see what I can do more or less and the following lack of understanding occurred to me. Perhaps it's just something I haven't gotten to yet in my learning (reading the W3 tutorials to learn Javascript), but... figured it can't hurt to ask.

So sorry for the bit of introduction, but my question is after the button is hit, and a number entered, what is it returned to? How do I access this to, for example, print it on the screen?



Code:
<html>
<head>

<script type="text/javascript">
function getNumber()
{
x = prompt("Enter a number between 1 and 10","");
return x;
}
</script>

</head>

<body>

<input name="numberButton" type="Button" onclick="getNumber()" value="Number Button" />
Your favorite number is: 

//Doesn't work, but I'm not sure why. x is terminated after closing the script I must assume, so what can be done to get the desired result?
<script type="text/javascript">
document.write(x);
</script>

</body>
</html>
Told you it was simple . Thanks for the help!
kryptobs2000 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-02-2010, 11:41 AM Re: What am I doing wrong here? (assigning variable through <input> button)
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
javascript is event driven so the function has to be called by an event occuring on the page.
A mouse movement action, a mouse button click action, the page loading or an element loading.

As it stands your "document.write" will have nothing to actually write.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to What am I doing wrong here? (assigning variable through <input> button)
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.09659 seconds with 12 queries