View Single Post
  #2 (permalink)  
Old Nov 29th, 2007, 11:45
Rakuli's Avatar
Rakuli Rakuli is offline
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
Reply With Quote