Submit Your Article Webforumz RegistrationAnnouncements Contact Webforumz StaffContact
Home Resources Blogs Meet the Team Contact Register
 

Go Back   WebForumz.com > The Code > JavaScript

Reply
 
LinkBack Thread Tools
Old November 29th, 2007, 06:26 AM   #1
New Member
 

Join Date: Nov 2007
Location: Hungary
Age: 24
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 hegerp is on a distinguished road
[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!
hegerp is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old November 29th, 2007, 07:45 AM   #2
Highly Reputable Member
SuperMember
 
Rakuli's Avatar
 

Join Date: Sep 2007
Location: Australia
Age: 25
Posts: 954
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 Rakuli is a splendid one to behold Rakuli is a splendid one to behold Rakuli is a splendid one to behold Rakuli is a splendid one to behold Rakuli is a splendid one to behold Rakuli is a splendid one to behold
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 Code:
<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
__________________
Luke Dingle . com
Rakuli is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old November 29th, 2007, 09:31 AM   #3
New Member
 

Join Date: Nov 2007
Location: Hungary
Age: 24
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 hegerp is on a distinguished road
Re: Javascript tutorial

Thank you very much.

the only part I stucked in because, that was
innerHTML

Now I know it!

Thank you again!
hegerp is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 4 January 18th, 2008 07:14 AM
[SOLVED] Email Submit Form Problem, The tutorial From The Php Forum longstand PHP 3 November 12th, 2007 04:06 PM
[Tutorial -> Trick] Link checking using JavaScript (ny myself) RohanShenoy JavaScript 7 November 8th, 2007 08:52 AM
[SOLVED] javascript from validation eon201 JavaScript 2 October 24th, 2007 01:41 PM
[SOLVED] JavaScript w/flash j04155 JavaScript 4 October 9th, 2007 09:25 AM


Search Engine Optimization by vBSEO 3.2.0 RC8