javascript - Cannot return from outside a function or method? -



javascript - Cannot return from outside a function or method? -

while developing web application want perform validation check , after sucesssful validation need post form , redirect command next page.

javascript code:

function fncheckemptyfield() { var strdomain = document.getelementsbyname("txtiidn").value; if (strdomain == null) { document.getelementbyid("lblvaliditystatus").innerhtml = ""; document.getelementbyid("lblvaliditystatus").innerhtml = "domain name field can't left blank"; homecoming false; } else { homecoming true; } }

relevant html code:

<form action="result.jsp" name="validitycheck" onsubmit="return fncheckemptyfield()"> <input type="text" id="txtiidn"/> <input type="submit" id="btnvaliditycheck" value="check validity" /> </form>

the line onsubmit="return fncheckemptyfield()" shows error cannot homecoming outside function or method , after execution of javascript function form getting submitted regardless text field blank or not.

i have placed alerts within if status , sure if field empty function returns false.

i don't know what's wrong code , why errors cannot homecoming outside function or method.

what's cause , how can solve it?

the line onsubmit="return fncheckemptyfield()" showing error cannot homecoming outside function or method

that's specific eclipse. eclipse wrong here, line fine. ignore eclipse error. if want, can disable js validation.

and after execution of java script function form getting submitted regardless text field blank or not.

that's because javascript function wrong. you've 2 mistakes in js code.

the getelementsbyname() phone call incorrect.

var strdomain = document.getelementsbyname("txtiidn").value;

to retrieve element id, need getelementbyid().

var strdomain = document.getelementbyid("txtiidn").value;

empty values not null, empty string.

if (strdomain == null)

you need check length instead.

if (strdomain.length == 0)

or create utilize of js boolean magic.

if (!strdomain)

by way, line document.getelementbyid("lblvaliditystatus").innerhtml = ""; unnecessary in code.

javascript html eclipse jsp

Comments

Popular posts from this blog

delphi - blogger via idHTTP : error 400 bad request -

c++ - compiler errors when initializing EXPECT_CALL with function which has program_options::variables_map as parameter -

How do I check if an insert was successful with MySQLdb in Python? -