November 06, 08 by Gabi Solomon
The ternary operator will accept three operands and is used to assign a certain value to a variable based on a condition. The syntax is condition ? result1 : result2;
So if the the condition is evalued as true the result1 is runned else result2.
Example:
JavaScript:
-
<script language=javascript>
-
var x=3;
-
(x == 3) ? y="true" : y="false";
-
document.write(y);
-
</script>
This will print out: true
Pretty simple, cheers.
June 19, 08 by Gabi Solomon
Today i found an interesting article about Tabs without JavaScript. Turns out you can do a tabbing system without needing to use JavaScript, only by CSS and standard (X)HTML. The downside is that you won't get styling on the active tab to indicate that it is active.
Here is the code:
CSS:
-
div.tabcontainer {
-
width: 500px;
-
background: #eee;
-
border: 1px solid #000000;
-
}
-
ul.tabnav {
-
list-style-type: none;
-
margin: 0;
-
padding: 0;
-
width: 100%;
-
overflow: hidden;
-
}
-
-
ul.tabnav a {
-
display: block;
-
width: 100%;
-
}
-
-
ul.tabnav a:hover {
-
background: #ccc;
-
}
-
-
ul.tabnav li {
-
float: left;
-
width: 125px;
-
margin: 0;
-
padding: 0;
-
text-align: center;
-
}
-
-
div.tabcontents {
-
height: 290px;
-
background: #ccc;
-
overflow: hidden;
-
border-top: 1px solid #011;
-
padding: 3px;
-
-
}
-
-
div.tabcontents div.content {
-
float: left;
-
width: 100%;
-
height: 102%;
-
overflow-y: auto;
-
}
-
-
div.tabcontents div.content h2 {
-
margin-top: 3px;
-
}
HTML:
-
<div class="tabcontainer">
-
-
<li><a href="#tab1">Tab 1
</a></li>
-
<li><a href="#tab2">Tab 2
</a></li>
-
<li><a href="#tab3">Tab 3
</a></li>
-
<li><a href="#tab4">Tab 4
</a></li>
-
</ul>
-
<div class="tabcontents">
-
<div class="content" id="tab1">
-
-
</div>
-
<div class="content" id="tab2">
-
-
</div>
-
<div class="content" id="tab3">
-
-
</div>
-
<div class="content" id="tab4">
-
-
</div>
-
</div>
-
</div>
Demo page
June 14, 08 by Gabi Solomon
On all my projects there was at least one delete buton or a diferent action that would be irevocable. And many times during the developing phase i forgot to put a method of preventing clicking that link by mistake. Of course you can do a confirmation page from php that would be better since it will not depend on the user having javascript activated, but during the developing phase it is better to put a simple javascript confirm even if you will develop a php confirmation page. This will save some load of the server if the user has javascript activated, and save the user some time. Also it is best to always have a confirmation method since many times the user is in a hurry to click and might click the worng button.
There are 2 methods of doing a javascript confirm.
Using a separate function
HTML:
-
-
function confirmDelete(delUrl) {
-
if (confirm("Are you sure you want to delete")) {
-
document.location = delUrl;
-
}
-
}
-
</script>
-
-
<a href="javascript:confirmDelete('delete.page?id=1')">Delete
</a>
Confirming directly in the link
HTML:
-
<a href="delete.page?id=1" onclick="return confirm('Are you sure you want to delete?')">Delete
</a>
I have gotten my slef used to use the last method on all my delete buttons even if i develop a confirmation page later on. It prevents even me from clicking the delete button by mistake
.
I hope this has been of some help to you.
Cheers
June 08, 08 by Gabi Solomon