I'm checking on some code my developer did for a form on our site.
The code relates to a submit button and I'm not sure if it's
functioning properly. I ran the javascript through javascriptlint. com/
online_lint.php and a few warnings popped up, but I'm not sure if
these warnings amount to much.
Here's the code for the submit button:
<input type="submit" name="next" class="btn"
onclick="saveBu ttonClicked(nam e, 'VehicleButton' );" onfocus="blur() "
value="Next Step" />
One thing I've noticed is that if a user gets a security warning after
clicking the submit button and then chooses No, the button dies and
they can't submit the form unless they reload the page. I took out the
onfocus="blur() " and still had the same problem.
The javascript code is below.
Any comments/suggestions/help will be tremendously appreciated.
function saveButtonClick ed(name, button) {
document.getEle mentById(button ).value = name;
}
function getElementByNam e(name) {
var elements = document.getEle mentsByTagName( "*");
for (var i=0; i < elements.length ; i++) {
var c = " " + elements[i].name + " ";
if (c.indexOf(" " + name + " ") != -1)
return elements[i];
}
return null;
}
function alertIfEmpty(id , message) {
// if element 'id' is empty, alert the user with 'message' and
return false
text = leftTrim(docume nt.getElementBy Id(id).value);
if (0 == text.length) {
alert(message);
document.getEle mentById(id).fo cus(); // set the focus to this
input
return false;
} else {
return true;
}
}
function leftTrim(sStrin g) {
while (sString.substr ing(0,1) == ' ') {
sString = sString.substri ng(1, sString.length) ;
}
return sString;
}
function selectGroup(nam e) {
select = document.getEle mentById(name). checked;
for (var i = 0; i < 1000; i++) {
box = document.getEle mentById(name + i);
if (null == box)
break;
else if (box.checked != select)
box.checked = select;
}
}
The code relates to a submit button and I'm not sure if it's
functioning properly. I ran the javascript through javascriptlint. com/
online_lint.php and a few warnings popped up, but I'm not sure if
these warnings amount to much.
Here's the code for the submit button:
<input type="submit" name="next" class="btn"
onclick="saveBu ttonClicked(nam e, 'VehicleButton' );" onfocus="blur() "
value="Next Step" />
One thing I've noticed is that if a user gets a security warning after
clicking the submit button and then chooses No, the button dies and
they can't submit the form unless they reload the page. I took out the
onfocus="blur() " and still had the same problem.
The javascript code is below.
Any comments/suggestions/help will be tremendously appreciated.
function saveButtonClick ed(name, button) {
document.getEle mentById(button ).value = name;
}
function getElementByNam e(name) {
var elements = document.getEle mentsByTagName( "*");
for (var i=0; i < elements.length ; i++) {
var c = " " + elements[i].name + " ";
if (c.indexOf(" " + name + " ") != -1)
return elements[i];
}
return null;
}
function alertIfEmpty(id , message) {
// if element 'id' is empty, alert the user with 'message' and
return false
text = leftTrim(docume nt.getElementBy Id(id).value);
if (0 == text.length) {
alert(message);
document.getEle mentById(id).fo cus(); // set the focus to this
input
return false;
} else {
return true;
}
}
function leftTrim(sStrin g) {
while (sString.substr ing(0,1) == ' ') {
sString = sString.substri ng(1, sString.length) ;
}
return sString;
}
function selectGroup(nam e) {
select = document.getEle mentById(name). checked;
for (var i = 0; i < 1000; i++) {
box = document.getEle mentById(name + i);
if (null == box)
break;
else if (box.checked != select)
box.checked = select;
}
}
Comment