473,327 Members | 2,118 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

onFocus and onClick for Submit Button

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[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(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;
}
}
Jun 27 '08 #1
1 2395
pa*********@yahoo.com writes:
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[i].name + " ";
if (c.indexOf(" " + name + " ") != -1)
return elements[i];
}
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.

--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
Jun 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Scott Navarre | last post by:
Hi, I have Red Hat 8.0 and have the default Mozilla browser that comes with it. I am programming in javascript and have come across something problematic. Given the following code: <HTML>...
1
by: Michael Albanese | last post by:
I am developing an application to handle my compay's OSHA reporting requirements. Some of the input criteria are technical and narowly defined, so I was trying to prvide what i call "Context...
1
by: David | last post by:
Here is the layout of my form from left to right, from top to down. - buttonA, buttonB, buttonC - textbox, textbox, textbox - buttonXXX After the user types in the textboxes and press enter...
2
by: Vinita Sharma | last post by:
Hi All, I have a strange problem. I have 2 text boxes and a button in my form. There is a function called on onchange event of the first text box. There is another function called on onclick...
4
by: Dmitry Korolyov [MVP] | last post by:
When we use btnSubmit.Attributes = "javascript: this.disabled=true;" to make the button disabled and prevent users from clicking it again while form data still posting, there is no longer...
2
by: Sedef | last post by:
Hi, i'm trying to create a custom Button user control which will be derived from System.Web.UI.WebControls.Button. the normal server side Button class creates some client side javascript code for...
0
by: none | last post by:
Hi, I’ve got a problem with my onclick handlers for command buttons being dropped on page render for a popup window. On the opening window, I have several command buttons, and they all have...
4
by: sameergn | last post by:
Hi, I have an image in my HTML form which has onclick() handler. There is also a submit button and a text box. Whenever text box has focus and user presses enter, the onclick() event of...
5
by: plumba | last post by:
Ok, another query.... I have a checkbox at the bottom of my form which when checked unhides a <div> block which displays the submit button. The problem I have is when the clear form button is...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.