[SOLVED] Javascript tutorial

This is a discussion on "[SOLVED] Javascript tutorial" within the JavaScript Forum section. This forum, and the thread "[SOLVED] Javascript tutorial are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Nov 29th, 2007, 10:26
New Member
Join Date: Nov 2007
Location: Hungary
Age: 22
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] Javascript tutorial

Hi!

I'm very new to javascript, I'm still a fresh learner and I've got trough some tutorials and I thought I understand the language too. I thought it just until the minute I've tried to do my first piece of code.

I ask you for help, please help me if you have time. I'd like you to make me a little example tutorial or a piece of code which I can understand better. I only need a few things...

I do need a variable (myvar) which is created in the <head>. (I've done that myself and worked The document should write this variable in some place of the <body> (document.write(myvar)) I've done that part too.
But I want it to be changeable the following way. I have some checkboxes which will represent some number (300, 390, 450). I want to create a function to be able to put an onClick event on the checkboxes so when the user checks checkboxes a certain amount would be added to the main variable.

I hope it was understandable. I hope someone will help me, and thanks for the lot beforehand!

Buh-Bye!
Reply With Quote

  #2 (permalink)  
Old Nov 29th, 2007, 11:45
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Javascript tutorial

Okay, this isn't such a daunting task to take on in your first attempt...

something like this (assuming you want the varible that is written in the body to be updated each time the checkbox is clicked)

this is very basic


HTML: Select all
<html>
<head>

<!-- head stuff ect //-->
<script type="text/javascript">
var myvar = 100; // declare the varible to be used later in the piece


// this function will be called when the checkboxes are clicked, it will change the value of 
// myvar and update the area on the page
function changeMyvar (varAmount)
{

    myvar = varAmount;
    document.getElementById('myvarHolder').innerHTML = myvar;
}


</script>
</head>
<body>
<!-- this span holds the value of my var and will be uupdated later //-->
<span id="myvarHolder">
<script type="text/javascript">
document.write(myvar);
</script>
</span>


<form>
<input type="checkbox" value="300" onclick="changeMyvar(300)" />
<input type="checkbox" value="390" onclick="changeMyvar(390)" />
<input type="checkbox" value="450" onclick="changeMyvar(450)" />
</form>
</body>
</html>

The above ^^, very simply, does what you ask I believe
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Reply With Quote
  #3 (permalink)  
Old Nov 29th, 2007, 13:31
New Member
Join Date: Nov 2007
Location: Hungary
Age: 22
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Javascript tutorial

Thank you very much.

the only part I stucked in because, that was
innerHTML

Now I know it!

Thank you again!
Reply With Quote
Reply

Thread Tools

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 On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
[Tutorial] Print links in printable version using javascript RohanShenoy JavaScript Forum 4 Jan 18th, 2008 11:14
[SOLVED] Email Submit Form Problem, The tutorial From The Php Forum longstand PHP Forum 3 Nov 12th, 2007 20:06
[Tutorial -> Trick] Link checking using JavaScript (ny myself) RohanShenoy JavaScript Forum 7 Nov 8th, 2007 12:52
[SOLVED] javascript from validation eon201 JavaScript Forum 2 Oct 24th, 2007 17:41
[SOLVED] JavaScript w/flash j04155 JavaScript Forum 4 Oct 9th, 2007 13:25


All times are GMT. The time now is 19:38.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43