Java Questions
Java Questions

Reputation: 7953

value is undefined in javascript

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?

Upvotes: 1

Views: 1600

Answers (1)

xdazz
xdazz

Reputation: 160843

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

var mode='<%=mode%>';
bodyOnLoad();

Upvotes: 3

Related Questions