In your HTML HEADER add this code
<script type="text/javascript">
function clearText(thefield){
if (thefield.defaultValue==thefield.value)
thefield.value = ""
}
</script>
In your html input tag add this code
onfocus="clearText(this);"
October 23rd, 2008 — JavaScript, Web Development
In your HTML HEADER add this code
<script type="text/javascript">
function clearText(thefield){
if (thefield.defaultValue==thefield.value)
thefield.value = ""
}
</script>
In your html input tag add this code
onfocus="clearText(this);"
February 8th, 2008 — JavaScript, MySQL, PHP, Web Development
Wrote this function to check email addresses already in a database, so I dont have to change pages, and check with javascript. Problem: it exposes your whole email list to the public in the source code, and the source code can become a monster length. So it isnt practical, but it works. (I'm not using it to check emails)
The script proves useful to do other things with javascript and spawn arrays to manipulate data... etc.
function jarray(){
$sql = "SELECT * FROM table_name LIMIT 0, 100000000";
$jarray = "var your_array = new Array();\n\t\t";
$i = 0;
$q = mysql_query($sql);
while($object = mysql_fetch_object($q)){
$jarray = $jarray."your_array[{$i}] = \"{$object->field_name}\";\n\t\t";
$i++;
}print $jarray."\n";
}
Put your own info where the Text is bold
February 8th, 2008 — JavaScript, Javascipt, Web Development
I've used many before, this is the cleanest without too much code. It features a nice onfocus clear value bonus. When the email is incorrect after click the alert box when the email is invalid, it will clear the mail input field value and bring the cursor directly to the the email input box. The email validation does not check is the email actually works, just is it appears valid, excellent for javascript!
December 16th, 2007 — CSS, JavaScript, Javascipt, Mac, Web Development
The letter-spacing is treated differently on OSX than Windows XP. This can cause problems if you basing a design off text-based CSS. This fix works perfectly if you using a simple dropdown menu that uses absolute positions and auto margins, so its not a child of the initial menu you made, an example can be seen here: www.cmcri.org
A simple javascript code can detect a MAC platform with an IF statement, IF it is MAC then write to document a style. This code must be inserted after your initial call for your style sheet so it overwrites the original CSS code.
if(navigator.userAgent.indexOf('Mac') != -1)
{document.write ('<style type="text/css">#header ul li a{letter-spacing:.025em;}</style>');}
Easy fix!
October 10th, 2007 — JavaScript, Javascipt, Web Development, wed developement
To add a variable mid string in javscript use the plus operator ( + )
Example:
var page;
page = "50";
document.write("Delete Page " + page + "?");
or when used within a function
function confirmDelete(delUrl,page) {
if (confirm("Delete Page " + page + "?")) {
document.location = delUrl;
}
}
November 19th, 2006 — JavaScript, Web Development
This script opens a window using the image dimensions as the control. When you do not want to jeopardize convention and need a Click to enlarge Button, use this code.
<script><!--
function imagePopUp(img) {
html = "<html><head><title>Enlarged Image</title>" + "</head><body style="margin: 0px 0; text-align:center; ">" + "<IMG src='" + img + "' BORDER=0 NAME=image " + "onload='window.resizeTo(document.image. width,(document.image.height*1.3))'>" + "</body></html>"; popup=window.open ('','image','toolbar=0,location=0, directories=0,menuBar=0, scrollbars=0,resizable=1'); popup.document.open(); popup.document.write(html); popup.document.focus(); popup.document.close() }; //--></script>
To call the script use a simple link.
<a href="javascript:imagePopUp('../images/yourimage.gif')"'>Click to enlarge</a>
This script is modified code found @ www.rgagnon.com
November 10th, 2006 — JavaScript, Web Development
Yahoo Stores can only take you so far. A client of mine uploads images of a product, if that image is too large it destroys the structure of the site. To fix this I would have to manually download all the images, resize them and re-upload them to Yahoo, or use JavaScript.
<script language="javascript" type="text/javascript">
<!--
function resize_images()
{
for (i = 0; i < document.images.length; i++)
{
while ( !document.images[i].complete )
{
break;
}
if ( document.images[i].width > 185 )
{
document.images[i].width = 185;
}
}
}
-->
</script>
It resizes all images. To avoid this one can edit the JavaScript to avoid images with a particular name, and/or use css background and text/image replacement techniques.
Since the script is controlled by the for statement loop, you can avoid resizing some images. Example: for (i = 0; i < document.images.length; i++) i = 0 is the image you start to resize, if this were 1 you would skip the first image. (say your first image was a header and didnt want to resize it) Where you findthe second 185 in the script is the minimum width an image must be for it to be resized. The second 185 controls the new width of your images. The last thing you must do is call the function in the body tag.
<body onLoad="resize_images();" >
This script creates a popping effect, which can be annoying, but ultimately it prevents a broken structure. Say the least it's a great temporary fix. I found javascript like this in Mike Lothar's PHPBB Theme Nosebleed v1.09