If you are a web programmer one of the most annoying things you have probably run across is the inability to make a dropdown (HTML Select tag) box read only. And another thing you don't like is reading some long post that really doesn't help you solve the issue you are trying to solve. So without taking anymore of your time, here is the code.
<head>
<script type="text/javascript">
function DisableField(fld){
var origfld = document.getElementById(fld);
var hidfld = document.createElement("input");
hidfld.setAttribute("type", "hidden");
hidfld.setAttribute("name", origfld.name);
hidfld.setAttribute("id", origfld.id);
hidfld.setAttribute("value", origfld.value);
origfld.id = fld + '_disabled';
origfld.name = fld + '_disabled';
origfld.disabled = true;
document.getElementById("PageForm").appendChild(hidfld);
}
</script>
</head>
<form id="PageForm">
<select name="Shop" id="Shop" >
<option >Select Shop</option>
<option >Shop1</option>
</select>
<!-- This has to go below the select field -->
<script type="text/javascript">DisableField('Shop');</script>
</form>
So what it does in short is you send it a field name and it renames the field and then creates a hidden field with the name and ID of the original field. So what you get is a disabled dropdown and a hidden field that contains the original value.
Friday, April 22, 2011
Thursday, March 10, 2011
The Underestimated Comment
As a programmer I am as guilty as the next guy about not commenting my code. But it really is an important ingredient in any piece of code. I have gone back into code I wrote a couple years ago ... eh who am I kidding even a couple months ago, and looked at the code and thought, "what was I doing that for?". I have also on numerous occasions had the opportunity to trouble shoot someone else's code, and let me tell you how much easier it is when it is well documented with comments in the code. So today I wanted to share with you just how to comment in several programming languages.
How to Comment in C#
// This is a comment in C# code
/* This is also a comment in C#
It can be used for comment multiple lines */
How to Comment in VB
' This is a comment in VB
How to Comment in CSS
/* This is a comment in CSS */
How to Comment in Javascript
// This is a comment in Javascript
How to Comment in HTML
<!-- This is a comment in HTML -->
How to Comment in Perl
# This is a comment in Perl
How to Comment in PHP
// This is a comment in PHP
/* This is also a comment in PHP
It can be used for comment multiple lines */
How to Comment in XML
<!-- This is a comment in XML -->
How to Comment in ASP (pre .Net)
' This is a comment in ASP
Wednesday, February 23, 2011
Stripping Tags From a Webpage
Ever need to take a beautifully formed webpage and strip out all the tags and junk to just see the text?
<?php
if (!isset($_POST["url"])){
echo "Enter URL: <form method='post' action='justtext.php'><input type='text' name='url'><input type='submit' value='submit'></form> ";
}
else{echo strip_tags(file_get_contents($_POST["url"] ));
}
?>
It is really pretty easy with the PHP strip_tags() function. The only catch is that when all the tags are removed, it leaves a pile of attributes. Which if you just need to strip out the text from a simple XML doc or something pretty basic it works great.
Here is the code. Just name the file justtext.php and have all the fun you can stand.
<?php
if (!isset($_POST["url"])){
echo "Enter URL: <form method='post' action='justtext.php'><input type='text' name='url'><input type='submit' value='submit'></form> ";
}
else{echo strip_tags(file_get_contents($_POST["url"] ));
}
?>
Tuesday, February 22, 2011
iPhone Blogging
I am writing this from my iPhone using an app called Blogspace. It is a free app and seems to have nice features. Like the ability to monitor multiple blogger blogs. Which brings me to the possible downside. I believe it only works with Blogger/Blogspot. So far I am enjoying the ability to blog on the go, if I ever get the urge too. Anyway if you have a Blogger/Blogspot blog and want to blog from your iPhone, you should give Blogspace a try, you can find it in the app store.
Monday, February 21, 2011
Woopra - Real Time Analytics
So last week I said good bye to Joomla and hello to Wordpress for our church's website.(www.boonvilleworshipcenter.org). I really like Wordpress as a content management system. It is a lot simpler than Joomla and more light-weight. I did have to tweak a few things to meet my needs, like making my posts page the listen to sermons page and customizing the template. But overall I really like it.
But that's really not what I want to tell you about. After setting up the new site I decided I needed to run some analytics. I set up Google analytics and am happy with it, but wanted something a little more real time. So I visited my close friend Google and came across http://www.woopra.com. Woopra is real time analytics that has some really cool features. You can log into their site and see live who is on your website. There are the basics like visitors, where they go and how they got to your site. But it is really cool to watch a visitor to your site go from page to page. Then there is the live chat feature. You can start a chat session with someone on your site and ask if they need help. They also have a Wordpress plugin, desktop app and an iPhone app. The best feature of Woopra is that it is free, at least for the first 30,000 hit per month.
If you are looking for a really nice real time analytics for your website you should check out Woopra.
Subscribe to:
Posts (Atom)