html - javascript not checking condition properly in case of span tag -



html - javascript not checking condition properly in case of span tag -

i have form , span. when click on submit button, calls function.

<form action="" method="post"> <span id="msg_check"> checkingfgr </span> <br/> <input type="submit" value="save" onclick="return valid()" /> </form> <script type="text/javascript"> function valid() { = document.getelementbyid("msg_check").innerhtml; if (a = "checking") { alert("hi") } else { homecoming false; } } </script>

now want if span contains checking should alert else homecoming false...but alerting in cases not going else part. when putting else in span tag still alerting, not calling function properly.

it going in if, because if(a="checking") assigning not comparing, thats reason goes in if block

use

if(a=="checking") { alert("hi"); }

if containg checking

if (a.indexof("checking") > -1) { alert('hi'); }

javascript html

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -