Friday, July 23, 2010

Javascript validate date - native

If somehow you are trying to validate dates that involves 2 drop downs and the values in the drop down are set, you can do the following.

function validateDate(dateToCheck, selectedDay)
var totalMonthCount = 12;
var i = 1;
var isValid = true;

var monthToCheck = parseInt(dateToCheck.getMonth());
var yearToCheck = parseInt(dateToCheck.getFullYear());

if(selectedDay > 28)
if(monthToCheck == 2)
if(yearToCheck%4 == 0)
if(selectedDay > 29)
isValid = false;
isValid = false;

if((monthToCheck == 4) || (monthToCheck == 6) || (monthToCheck == 9) || (monthToCheck == 11))
if(selectedDay > 30)
isValid = false;

return isValid;

Mobile web development issues

Show-Hide display
To show-hide a loading screen, you would have to ensure that javascript does an unload on the body tag.

In it, you would want to hide (css display = 'none') for the loading screen section. I've used DIVs for the loading screen section.

HTML links & runat="server"
You will have to ensure that the "href" attribute contains "javascript:;" in the event that you intend to add the runat="server" attribute to your HTML links.

Thursday, July 22, 2010

Software Development - Project Managers

This post is a rant. If you don't like a rant, I suggest skipping this.

I am intruiged at the fact that IT Project Managers will allow untested software to be released to the world.

I am beginning to feel that in the corporate world, software developers are the most unappreciated people and also I am having the inkling that project managers are not operating at effective levels.

According to wikipedia, project management is the discipline of planning, organizing, and managing resources to bring about the successful completion of specific project goals and objectives.

And if a software developer is a resource to the project, my argument is, does this mean that the resource is not being managed properly? Does this than equate to the fact that the project manager is not performing their role to a sufficient and acceptable level?

Yes, sufficient and acceptable is subjective, however, when a Software Development project is over cost, delivered past the deliverable date, who is to blame?
From experience, the blame falls squarely at the feet of the developer. The word around the water cooler is, "so and so is doing a bad job, he's not delivering the project". However, my question is, is the developer solely to be blamed for the ludicrious time-line and deliverable date set by the Project Manager?

My question than is, who set the time-line?

Who spoke to the client and made the promise to the client that at a certain date, the project is going to be delivered?

Do they understand the intricacies of software development?

Was testing done prior to release?

Does the project manager understand that the computer is nothing but a dumb terminal that has to be told in specific fine minute details to perform a certain task?

Tuesday, July 20, 2010

dotNet URL

Using the HTTP Request object from the current HTTP context, can return a few different URL path.

To retrieve just the URL without the query string variables, use

To retrieve the entire URL with query string variables, use

There are other important bits that we can use too.

Friday, July 16, 2010

ASP.Net custom validator with javascript

To validate controls using javascript, just so you can use it for XUI or jQuery or whatever Web 2.0 library you use, you can simply declare a ASP.Net Custom Validator as such and have the ClientValidationFunction to be your javascript validator function;

<asp:CustomValidator ID="someVal" runat="server" ClientValidationFunction="jsValidator"></asp:CustomValidator>

Then, in the section of where your javascript code resides, can be in a file or at the top of the same page, declare a function as such.

function jsValidator(args, sender)
    //Insert validation here.
    //To set the error message on the ASP.Net validator control, just use the
    //sender object as such;
    //sender.errormessage = "Some error message";
    //Also, remember to set the isValid boolean flag, "args.IsValid"

Javascript - retrieving the drop down selected value

I copied this from the Tek-Tips forum just so I have a repository of it.

<title>New Page 10</title>
<script Language="JavaScript">
function checkData()

var myTest = me.D1.selectedIndex.value;



<form method="POST" name="me">
<select size="1" name="D1" onChange="checkData()">
<option value="99">Default</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>



selectedIndex, when used correctly, returns the index (number) of the space in the options collection in which the selected option resides.

Here's what you want to use:


I think that's it. Try the following if not:


Thursday, July 15, 2010

ASP.Net hidden fields and XUI

After fiddling around with XUI, I realized that there is no function within to retrieve the hidden input values similar to jQuery.

Thus, the hacked way around it is to declare a HTML tag, eg: a span, paragraph or even div and make the CSS display style as hidden.

You will also have to assign it a class and then you will be able to obtain it using XUI and plain ol' javascript by using the XUI selector and then adding .elements[0].innerHTML to the end of it.

NOTE: Javascript is case sensitive and innerHTML doesn't work if you'd typed it innerHtml

Wednesday, July 14, 2010

XUI JS return false

When creating a HTML link and using XUI, you will HAVE to set the OnClick function of the HTML link tag to contain "return false;".

This is done as XUI events do not implement "return false" properly

Sunday, July 4, 2010

jQuery date picker

To have this working,

1. Include the jQuery UI javascript file into your page.

2. Create an input field and assign it a class. For the purposes of this example, I shall name the input field class, "testDatePicker"

2. Have a jQuery.Document.Ready function and within it, apply the following code.

dateFormat: 'dd/mm/yy',
showOn: 'both',
buttonImage: '/images/buttons/cal.png',
buttonImageOnly: true,
onSelect: function(){
//Insert any form of logic you will have.
//NOTE: it will have to be in the JavaScript syntax

Friday, July 2, 2010

jQuery alternating show and hide ...continued

After performing what I thought solve the issue, I came up with another blockage.

The technique from my previous posting worked brilliantly but it wasn't how I wanted it.

This post will further illustrate what I mean.

You see, what I set out to do was to allow the 'jQuery alternating show and hide' individually for each data row.

Let me explain.

I have a list of some data. For the purpose of this example. Lets use HTML unordered-list items.


I had a HTML link (a-href tag) and a HTML paragraph (p tag) in each HTML li tag (see above). The a-href tag was suppose to perform the 'jQuery alternating show and hide' on the p tag.

Within the p tag, there lies the data.

Thus, to solved this, do the following.

1. Create a ASP.Net literal tag to replace the a-href tag.
If you are binding data to a repeater like what I am doing, you can simply access the ASP.Net literal tag in the OnItemDataBound event of the repeater.

2.Use the IF-ELSE statement from Step 5 of the previous post and convert that into a string.

NOTE: open & close swiggly brackets will have to be done twice for each instance.
This caught me out and I was having string issues when building my code.

3. After converting the IF-ELSE statement of Step 5 of the previous post to a string, append the converted string such that it make a distinction on each a-href tag.
The way I did this was to append "_" followed by the ID obtained from the data.

NOTE: Remember to include "return false;" after you've completed the IF-ELSE statement, if not the page will reload to the top of the page!

4. You will also have to append the p tag to used the same method as mentioned in Step 3.

Build your code and

TA-DAH, you're done!

jQuery alternating show and hide

Recently I was working on an iPhone WAP and required to alternate the jQuery show and hide.

This is a How-To to do such an event.

1. Create a HTML A-Href tag and specify the class value of it. For the purposes of this example, I shall call it 'hrefTest'.

<a href="#" class="hrefTest">Some test link</a>

2. Create the hidden field. For the purpose of this example, I am going to create a HTML P tag and assign the class value of this P tag to 'test' and also specify in the style value of the P tag of display: none.

<p class="test" style="display: none">Some test value</p>

3. Ensure that you have the jQuery library file (jQuery-1.4.2.min.js) or similar has been referenced at the top of the page.
This is something that I often forget to do

4. Declare another script tag and include the jQuery document.ready function.

5. Within the jQuery document.ready function, insert the following

if($(".test").css("display") == "none")

And walah, you have yourself a HTML link that will alternate between showing and hiding some text or whatever data.