Hi guys,
I seem to have come across a weird issue in internet explorer.
I've been working on doing regular expressions for a register form, and I've checked it in Firefox, and Chrome and it seems to work for both of them but yet it doesn't work for Internext Explorer 6 - 8.
The issue is that the drop down boxes (select fields) dont seem to be recognised for RegEx in I.E. this is causing an issue for me as I want it to work in ALL common web browers as well as keeping the whole form standard.
I've pasted a snippet of code below to show you what I've done.
This one below is the original one which just checks if the field entry is blank
function check(theForm)
{
var checker;
// Select fields alternate test
var day = theForm.day.value;
var month = theForm.month.value;
var year = theForm.year.value;
var gender = theForm.gender.value;
// Gets all label and div tag fields into a variable fo testing later
var age = document.getElementById('userAge');
var userGender = document.getElementById('userGender');
if (day == "")
{
var adder = age.innerHTML + "";
adder = '<label class="incorrect" id="userAge"> *Date Of birth*: </label>';
age.innerHTML = adder;
checker = false;
}
else if (month == "")
{
var adder = age.innerHTML + "";
adder = '<label class="incorrect" id="userAge"> *Date Of birth*: </label>';
age.innerHTML = adder;
checker = false;
}
else if (year == "")
{
var adder = age.innerHTML + "";
adder = '<label class="incorrect" id="userAge"> *Date Of birth*: </label>';
age.innerHTML = adder;
checker = false;
}
else
{
var adder = age.innerHTML + ""; // a new variavble is created which is the innerHTML through the changer fields
adder = '<label class="loginLabel" id="userAge"> Date Of birth: </label>'; // changes the current div tag into the innerHTML field
age.innerHTML = adder; // changes the innerHTML to equal the adder
}
if (gender == "")
{
var adder = userGender.innerHTML + "";
adder = '<label class="incorrect" id="userGender"> *Gender*: </label>';
userGender.innerHTML = adder;
checker = false;
}
else
{
var adder = userGender.innerHTML + ""; // a new variavble is created which is the innerHTML through the changer fields
adder = '<label class="loginLabel" id="userGender"> Gender: </label>'; // changes the current div tag into the innerHTML field
userGender.innerHTML = adder; // changes the innerHTML to equal the adder
}
}
This next one is an actual regular expression test using 2 methods which work on all other fields I have in the form (And also I tested them in FF and Chrome)
function check(theForm)
{
var checker;
// Select fields alternate test
var day = theForm.day.value;
var month = theForm.month.value;
var year = theForm.year.value;
var gender = theForm.gender.value;
// Gets all label and div tag fields into a variable fo testing later
var age = document.getElementById('userAge');
var userGender = document.getElementById('userGender');
var letterTest = /(^[A-Z|a-z\s]+$)/; // checks to see if the letters are the only entry (or if its blank)
var numberTest = /([0-9]+$)/; // ensures that there is at least one number in the field
if (numberTest.test(day) == false)
{
var adder = age.innerHTML + "";
adder = '<label class="incorrect" id="userAge"> *Date Of birth*: </label>';
age.innerHTML = adder;
checker = false;
}
else if (letterTest.test(month) == false)
{
var adder = age.innerHTML + "";
adder = '<label class="incorrect" id="userAge"> *Date Of birth*: </label>';
age.innerHTML = adder;
checker = false;
}
else if (numberTest.test(year) == false)
{
var adder = age.innerHTML + "";
adder = '<label class="incorrect" id="userAge"> *Date Of birth*: </label>';
age.innerHTML = adder;
checker = false;
}
else
{
var adder = age.innerHTML + ""; // a new variavble is created which is the innerHTML through the changer fields
adder = '<label class="loginLabel" id="userAge"> Date Of birth: </label>'; // changes the current div tag into the innerHTML field
age.innerHTML = adder; // changes the innerHTML to equal the adder
}
if (letterTest.test(gender) == false)
{
var adder = userGender.innerHTML + "";
adder = '<label class="incorrect" id="userGender"> *Gender*: </label>';
userGender.innerHTML = adder;
checker = false;
}
else
{
var adder = userGender.innerHTML + ""; // a new variavble is created which is the innerHTML through the changer fields
adder = '<label class="loginLabel" id="userGender"> Gender: </label>'; // changes the current div tag into the innerHTML field
userGender.innerHTML = adder; // changes the innerHTML to equal the adder
}
}
If you have any Ideas about what I can do to make it work in I.E. I would be most greatful. Also if anyone knows how to do and RegEx on a checkbox that would help me quite a bit too.
Thanks in advance,
Your Freidnly Neighbourhood,
Ghost