onFocus and onClick for Submit Button

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;
}
}
 
J

Joost Diepenmaat

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" />

Ok, so you're using the saveButtonClicked and blur functions. You didn't
post the code of the blur function here...
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.

What does the warning say? It may not have anything to do with the
javascript.
The javascript code is below.

Any comments/suggestions/help will be tremendously appreciated.

function saveButtonClicked(name, button) {
document.getElementById(button).value = name;
}

This is just silly.
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;
}


That function is just wrong. But it will work for unique names that
don't contain spaces. Note that there isn't any requirement for a name
to be unique and names may contain spaces. I don't know if that makes
any difference, since it appears to not be called in your code.

I'll ignore the rest. None of it is relevant without more input from
you. Probably because you left out the definition of the blur function
and the exact warning you recieve or any other reasons you may have to
suspect that the code you've submitted actually doesn't do what it
should do.

Note that although general javascript questions are welcome here, this
is pretty much a forum for technical discussions. I (and probably most
people here) expect you to do *some* work yourself. Just dumping a lot
of code in our laps and expecting us to work out what the problem is and
what you want it to do is't likely to work. Unless, ofcourse, you're
willing to pay someone.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top