1

Take a look at this:

if(session.getAttribute("mode")!=null){
    mode = (String)session.getAttribute("mode");
}

The first time value for the mode is empty so I set the mode value to a script variable like this:

var mode='<%=mode%>';

below is the method in which I call on load of the form, but it says mode is undefined

bodyOnLoad();
var mode='<%=mode%>';
alert("mode : "+mode);
function bodyOnLoad() {
    if(mode.length < 0){
        alert("mode empty 111111");
        document.getElementById("functiontype").value="view";
        document.getElementById("page").value="1";
        document.forms["frmTempcard"].submit(); 
        return;
    }                       
}

Can anyone help me with this?

2
  • i am sorry forgot to mention, it is jsp Commented Aug 9, 2012 at 10:01
  • 1
    Note that you are calling the function bodyOnLoad before you set the value of mode. Commented Aug 9, 2012 at 10:05

1 Answer 1

3

Declare the variable first. The mode is undefined when you call the function bodyOnLoad.

var mode='<%=mode%>';
bodyOnLoad();
Sign up to request clarification or add additional context in comments.

1 Comment

thanks @xdazz it helped but now the form is not getting submitted even when the mode becomes empty, am i making any problem here ` if(mode.length < 0)`

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.