P
partlocator
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="saveButtonClicked(name, '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 saveButtonClicked(name, button) {
document.getElementById(button).value = name;
}
function getElementByName(name) {
var elements = document.getElementsByTagName("*");
for (var i=0; i < elements.length; i++) {
var c = " " + elements.name + " ";
if (c.indexOf(" " + name + " ") != -1)
return elements;
}
return null;
}
function alertIfEmpty(id, message) {
// if element 'id' is empty, alert the user with 'message' and
return false
text = leftTrim(document.getElementById(id).value);
if (0 == text.length) {
alert(message);
document.getElementById(id).focus(); // set the focus to this
input
return false;
} else {
return true;
}
}
function leftTrim(sString) {
while (sString.substring(0,1) == ' ') {
sString = sString.substring(1, sString.length);
}
return sString;
}
function selectGroup(name) {
select = document.getElementById(name).checked;
for (var i = 0; i < 1000; i++) {
box = document.getElementById(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="saveButtonClicked(name, '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 saveButtonClicked(name, button) {
document.getElementById(button).value = name;
}
function getElementByName(name) {
var elements = document.getElementsByTagName("*");
for (var i=0; i < elements.length; i++) {
var c = " " + elements.name + " ";
if (c.indexOf(" " + name + " ") != -1)
return elements;
}
return null;
}
function alertIfEmpty(id, message) {
// if element 'id' is empty, alert the user with 'message' and
return false
text = leftTrim(document.getElementById(id).value);
if (0 == text.length) {
alert(message);
document.getElementById(id).focus(); // set the focus to this
input
return false;
} else {
return true;
}
}
function leftTrim(sString) {
while (sString.substring(0,1) == ' ') {
sString = sString.substring(1, sString.length);
}
return sString;
}
function selectGroup(name) {
select = document.getElementById(name).checked;
for (var i = 0; i < 1000; i++) {
box = document.getElementById(name + i);
if (null == box)
break;
else if (box.checked != select)
box.checked = select;
}
}