0

I've got this form on a JSP:

<form name="<%=formName%>" method="post" action="<%=actionURL%>" target="_parent" onsubmit="submitForm('<%=String.valueOf(isAbstract)%>','<%=formName%>'); return false">

Then I have the following Javascript in an include file:

function submitForm( isAbstract , formName ) {
    var o = "document.forms['" + formName + "']";
    var form = eval(o);
    if (isAbstract)
    {
            alert("Error");
            return;
    }
    if (!form.AutoName.checked)
    {
        if (form.name.value == "")
        {
            alert("Some text");
            return;
        }
    }
}

Well, I reduced the functions to make it simpler, but the thing is that whatever I do, I keep getting undefined values for both arguments. This is driving me crazy, because I've got similar code on other tags that work just fine (except that it's on a combo box tag with the onChange action).

Any thoughts, please?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
gaudi_br
  • 183
  • 2
  • 12
  • Open page in browser, rightclick, *View Source*, does it look right? You should **not** see any Java/JSP code in there. – BalusC Feb 03 '11 at 12:19

2 Answers2

1

I see that you are submitting the form to parent frame by using target attribute. Are you submitting the values from child iframe to parent window? If yes, does this form exist in parent frame?

Alterantively, you can simply pass "this" and access that as a form object.

For example,

<form onsubmit="submitForm(this)">

function submitForm(formObj){
  var fieldTxt1Value = formObj.txt1.value;

}

user243542
  • 241
  • 7
  • 20
  • I'm havin trouble doing line returns in this comment. Thanks for your reply, but that didn't quite work. The application I'm working on is a huge salad of frames so I'm submitting the values to a parent frameset. Either way, the HTML of the resulting page comes evaluated correctly as 'onSubmit=submitForm(1,'engDoc')' which in my opinion should suffice so that the javascript receives the value. However, even when I replace for "this", it evaluated as undefined. – gaudi_br Feb 03 '11 at 02:38
0

try to place a return false; At end of your func.

Looking your code, you're testing if the first parameter is true. But it is a string all the time, because you write quotes in call. It's what you want?

  • not really, I want it to evaluate to true or false. However, I couldn't see this problem, since whatever I do, even if the HTML shows the correct values of the JSP variable (formName and isAbstract evaluate to 'engDoc' and 'true' respectively), when I try to debug the javascript with firebug I only see "undefined" on everything inside the function. – gaudi_br Feb 03 '11 at 02:47
  • Just confirming after retrying over and over again, my biggest issue is that whatever values I pass, quoted or unquoted, they always evaluate to undefined, even if I pass 'this' as argument hoping to get the form object itself. I also trying removing the target=_parent thinking this could be the issue. – gaudi_br Feb 03 '11 at 02:53