Monday, September 27, 2004
Restaurant Puzzler answer...
The answer is that the figures will not add to £30 because they are not from the same equation. Equation 1: What's been paid is £25 for the meal - which is in the till, and £2 for the tip - in the waiter's pocket, leaving the men with £1 each, ie £3, which all adds up to £30. Equation 2: The men have each paid £9 for the meal and the tip together, ie £27, and they each have a £1 in their pocket, ie £3, which all adds up to £30.
Friday, September 24, 2004
Restaurant puzzler...
Three men eat at a restaurant. The bill comes to £25. They each pay £10. When the waiter brings the £5 change they take back £1 each and leave a £2 tip. So each man has paid £9, which totals £27. The waiter has the £2 tip, which makes £29, so where's the other £1 gone?
Answer to follow later
Answer to follow later
One selected option selects the option in another select box
I was asked by a colleague if this was possible - so I quickly wrote a javascript function. If you want to go by the value of anoption you will have to amend the code slightly.
<html>
<title>One selected option selects the option in another select box</title>
<head>
<script language="JavaScript">
function setSelectedOption() {
//get the number of the selected option - first option is 0
var selectedOption = document.formName.selectName1.selectedIndex;
//Check that one has been selected
if (selectedOption > -1) {
//set the same selected option for the second select box
document.formName.selectName2.options[selectedOption].selected = true;
}
}
</script>
</head>
<body>
<form name="formName"><div align="center">
<p>
<select name="selectName1" size="1"onchange="setSelectedOption();">
<option value="" selected="selected">-----------</option>
<option value="1">First Choice</option>
<option value="2">Second Choice</option>
<option value="3">Third Choice</option>
</select>
</p>
<p>
<select name="selectName2" size="1">
<option value="" selected="selected">---------</option>
<option value="1">First Choice</option>
<option value="2">Second Choice</option>
<option value="3">Third Choice</option>
</select>
</p>
</div></form>
</body>
</html>
<html>
<title>One selected option selects the option in another select box</title>
<head>
<script language="JavaScript">
function setSelectedOption() {
//get the number of the selected option - first option is 0
var selectedOption = document.formName.selectName1.selectedIndex;
//Check that one has been selected
if (selectedOption > -1) {
//set the same selected option for the second select box
document.formName.selectName2.options[selectedOption].selected = true;
}
}
</script>
</head>
<body>
<form name="formName"><div align="center">
<p>
<select name="selectName1" size="1"onchange="setSelectedOption();">
<option value="" selected="selected">-----------</option>
<option value="1">First Choice</option>
<option value="2">Second Choice</option>
<option value="3">Third Choice</option>
</select>
</p>
<p>
<select name="selectName2" size="1">
<option value="" selected="selected">---------</option>
<option value="1">First Choice</option>
<option value="2">Second Choice</option>
<option value="3">Third Choice</option>
</select>
</p>
</div></form>
</body>
</html>
Thursday, September 23, 2004
Toggling check box selection
I had to write this code to ensure that if a certain checkbox was selected it deselected another one and vic-versa. Why not use a radio button group I hear you ask, but if more than one select box can be selected from a group of 5 then this is not possible with radio buttons.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Checkbox checking...</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">
function toggleA() {
var materialA = document.getElementsByName("cBox_A")[0];
var materialB = document.getElementsByName("cBox_B")[0];
materialA.checked = true;
materialB.checked = false;
}
function toggleB() {
var materialA = document.getElementsByName("cBox_A")[0];
var materialB = document.getElementsByName("cBox_B")[0];
materialA.checked = false;
materialB.checked = true;
}
</script>
</head>
<body>
<form action="next_file.asp" method="post" enctype="multipart/form-data" name="form_name" id="form_name">
<input name="cBox_A" type="checkbox" value="Value A" onClick="toggleA()">Checkbox A<br>
<input name="cBox_B" type="checkbox" value="Value B" onClick="toggleB()">Checkbox B</form>
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Checkbox checking...</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">
function toggleA() {
var materialA = document.getElementsByName("cBox_A")[0];
var materialB = document.getElementsByName("cBox_B")[0];
materialA.checked = true;
materialB.checked = false;
}
function toggleB() {
var materialA = document.getElementsByName("cBox_A")[0];
var materialB = document.getElementsByName("cBox_B")[0];
materialA.checked = false;
materialB.checked = true;
}
</script>
</head>
<body>
<form action="next_file.asp" method="post" enctype="multipart/form-data" name="form_name" id="form_name">
<input name="cBox_A" type="checkbox" value="Value A" onClick="toggleA()">Checkbox A<br>
<input name="cBox_B" type="checkbox" value="Value B" onClick="toggleB()">Checkbox B</form>
</body>
</html>
Tuesday, September 21, 2004
Simple javascript alert
I was just asked by a colleague about a very simple javascript problem - he wanted a confirmation pop up but his code wasn't working properly. So here is the code
script
//confirmation - onclick event
function checkDelete(){
if(confirm("Are you really sure you want to format your hard drive?"))
{
return true;
}
else
{
return false;
}
}
/script
the button code
input name="btn_delete" type="button" id="btn_delete" value="Delete" onClick="return checkDelete();"
He had missed out the return in the onClick event.
script
//confirmation - onclick event
function checkDelete(){
if(confirm("Are you really sure you want to format your hard drive?"))
{
return true;
}
else
{
return false;
}
}
/script
the button code
input name="btn_delete" type="button" id="btn_delete" value="Delete" onClick="return checkDelete();"
He had missed out the return in the onClick event.
Hello World
I thought I'd just give this blogging a go. I read quite a few but have thought it was too much work to maintain it. We will see.
Subscribe to:
Posts (Atom)