onFocus and onClick for Submit Button

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • partlocator@yahoo.com

    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="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;
    }
    }
  • Joost Diepenmaat

    #2
    Re: onFocus and onClick for Submit Button

    partlocator@yah oo.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="saveBu ttonClicked(nam e, 'VehicleButton' );" onfocus="blur() "
    value="Next Step" />
    Ok, so you're using the saveButtonClick ed 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 saveButtonClick ed(name, button) {
    document.getEle mentById(button ).value = name;
    }
    This is just silly.
    >
    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;
    }
    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/

    Comment

    Working...