Why won't this onsubmit action fire?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • KathyB

    Why won't this onsubmit action fire?

    Hi, I have the following submit code:

    <form name="finish" action="Hidden_ Birth2.aspx" method="post"
    onsubmit="retur n CheckInput(this );">
    <input style="CURSOR: HAND" type="submit" name="finish"
    value="FINISH"/>
    <b>Click the FINISH button when work instruction is complete.</b>
    </form>

    and here is my CheckInput script:

    function CheckInput()
    {
    var cnAll = document.all;
    for (var i=0;i<cnAll.len gth;i++)
    {
    if(cnAll(i).tag Name=='input' && cnAll(i).type== 'text')
    {
    alert("You must first complete and SAVE all user inputs!");
    return false; }
    }
    }

    ....seems to work as far as checking for the elements (type=text), but
    if it does not return false; the action of the form (loading the aspx
    page) doesn't seem to work. I'm working in asp.net, and I just get a
    blank page. Since it is in the hmtl and if the js fails, still can't
    figure out HOW to find the problem...since it just quits.

    Any help appreciated.

    Kathy
  • Lasse Reichstein Nielsen

    #2
    Re: Why won't this onsubmit action fire?

    KathyBurke40@at tbi.com (KathyB) writes:
    [color=blue]
    > <form name="finish" action="Hidden_ Birth2.aspx" method="post"
    > onsubmit="retur n CheckInput(this );">[/color]

    You send the form to CheckInput as an argument, but doesn't use it.
    [color=blue]
    > <input style="CURSOR: HAND" type="submit" name="finish"
    > value="FINISH"/>[/color]

    You appear to use XHTML. I would put a space before the final "/>",
    just to not confuze older non-XHTML browsers.

    The correct CSS for what you want is "cursor:pointer ". The "hand" is
    an IE invention. For backwards compatability with IE 4, you can use both,
    with "hand" last.
    [color=blue]
    > function CheckInput()[/color]

    function CheckInput(form )

    (you pass the form anyway)
    [color=blue]
    > {
    > var cnAll = document.all;
    > for (var i=0;i<cnAll.len gth;i++)
    > {
    > if(cnAll(i).tag Name=='input' && cnAll(i).type== 'text')[/color]

    document.all is a collection, so you might want to use it as such, and
    not as a function. I.e., "cnAll[i]" instead of "cnAll(i)".


    You want to iterate through all the elements of the page and
    find the ones that are input elements with type "text". There
    are faster ways to do that (especially if you only check inside
    the form):

    var inputs = (form.getElemen tsByTagName?
    form.getElement sByTagName("inp ut"):
    form.all.tags(" input")); // for IE 4

    for (var i = 0; i < inputs.length; i++) {
    if (inputs[i].type == "text")

    [color=blue]
    > {
    > alert("You must first complete and SAVE all user inputs!");
    > return false; }
    > }
    > }
    >
    > ...seems to work as far as checking for the elements (type=text), but
    > if it does not return false; the action of the form (loading the aspx
    > page) doesn't seem to work. I'm working in asp.net, and I just get a
    > blank page.[/color]

    So the form *is* submitted, the asp.net just doesn't give the result
    you expected. That probably means that the bug is in the asp code.
    [color=blue]
    > Since it is in the hmtl and if the js fails, still can't
    > figure out HOW to find the problem...since it just quits.[/color]

    You can try making an asp page that displays the form elements
    that are submitted, and set the form to point to that page. Then
    you can see what is submitted.

    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    Working...