CODING
-
Simple function to see if a number is Even or Odd.
Sometimes you need to check if a number is even or odd. A simple way to do this is using the modulus operator (the %-sign). It will calculate and return the remainder when dividing a value with another value. So how do you use that to find out if a number is even or odd?…
-
(C#) Scroll to bottom of a textbox
Short snippet: [c language=”#”] textBox.SelectionStart = textBox.TextLength; textBox.ScrollToCaret(); [/c]
-
(PHP) Simple e-mail contact form.
A simple contact form, just for reference. Will add more info later on… [php] <?php if (isset($_POST[‘submit’])) { $name = $_POST[‘name’]; //name of sender $email = $_POST[’email’]; //e-mail of sender $email = stripslashes($email); $subject = $_POST[‘subject’]; //e-mail subject $subject = str_replace(array("\r\n","\r","\n"), "", $subject); //remove any linebreaks to keep from code injections $message = $_POST[‘message’]; //…
-
A couple of principles when learning how to code.
Principle 1. Always have a clear image of what you want to do BEFORE you start writing your code. Then break it down in logical instructions – making an algorithm. An algorithm is a step by step instruction on how to solve a specific problem. You might think of it as a recipe. If you…
-
Hide elements with radio buttons
Sometimes you want to show or hide certain elements of a form, depending on the selection of a radiobutton. I am by no means any javascript ninja, but this is one simple way I came up with: This could apply to any element. For example, you could put a whole bunch of elements in…
-
Hide elements with checkbox
This is a slightly edited version of this post. Just to make it work with a checkbox instead of radio buttons. [html] <html> <head> <script type="text/javascript"> function DisplayElement(checked) { if (checked) { document.getElementById(‘text’).style.display = ”; } else { document.getElementById(‘text’).style.display = ‘none’; } } </script> </head> <body> <form name="form"> <input type="checkbox" onclick="DisplayElement(this.checked)" checked/> <input…
-
(PHP) How to make a simple gallery
This is just a VERY basic gallery that you can modify to suit your needs. For example you could add columns in the database and store more info about the images (date, size, tags etc.). You could very easily make the output use Lightbox or similar images viewers. And you could of course do a…