:: iDavidStudio ::..

Dev log

Archive for September, 2011

Reg Exp For Valid Email

without comments

For Javascript

1
var regex = /^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i;

Written by admin

September 9th, 2011 at 3:27 pm

Posted in Programming

Radio button and checkbox not showing the selected value issue (IE8)

without comments

When trying to print a page that with radio button or checkbox on a IE 8 browser, you will notice that the correct radio button that you had checked did not show on the print. Instead, it is only showing the default one. To fix this issue, here are the javascript that you need:

1
<script type="text/javascript">
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// --- For Checkbox
function toggleCheckBox(checkBoxObj) {
    if ( checkBoxObj.getAttribute('checked') != 'checked' ) {
        checkBoxObj.setAttribute('checked','checked');
    }
    else {
        checkBoxObj.removeAttribute("checked");
    }
}
 
// --- For Radio buttons
function toggleRadio(radioBtnObj) {
    var groupName = radioBtnObj.name;
    var checkedId = radioBtnObj.id;
    var groupBtnNodes = document.getradioBtnObjementsByName(groupName);
    for (var i = 0; i < groupBtnNodes.length; i++) {
        if (groupBtnNodes[i].id == checkedId)
            groupBtnNodes[i].setAttribute('checked', 'checked');
        else
            groupBtnNodes[i].removeAttribute('checked');
    }
}
1
</script>
1
2
3
4
5
<!--On the HTML file-->
<input name="chk1" type="checkbox" id="chk1" onclick="toggleCheckBox(this)" />
<input name="chk2" type="checkbox" id="chk2" onclick="toggleCheckBox(this)" />
<input name="r1" type="radio" id="r1" onclick="toggleRadio(this)" />
<input name="r1" type="radio" id="r1" onclick="toggleRadio(this)" />

Written by admin

September 7th, 2011 at 5:32 pm

Posted in Programming