Solved

what is wrong with this code?

Posted on 2011-09-07
4
150 Views
Last Modified: 2012-05-12
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>testeeeee</title>

<script language="JavaScript" type="text/javascript">

<!--

var st="!#ana@.$";

function f1(info,s)
{
for(var i=0;i<info.length;i++)
{
if (s.indexOf(info.charAt(i))==1)
{
return (true);
}
 }
 return(false);
 }
 if(f1(document.forms[0].elements[0].value,st)==true)
 {
 alert("xyz");
 }
 else{alert("abc"); }
 

//-->
</script>
</head>
<body>
</body>
</html>
0
Comment
Question by:costaf
  • 2
4 Comments
 
LVL 28

Expert Comment

by:strickdd
ID: 36496204
What are you trying to accomplish and what is the code currently doing?
0
 
LVL 82

Expert Comment

by:leakim971
ID: 36496288
first look, there's not FORM element so you CAN'T USE  : forms[0]

should be good to wiat total page loading with something like :

window.onload = function() { // your code here }


var st="!#ana@.$";

function f1(info,s) {
    for(var i=0;i<info.length;i++)
    {
        if (s.indexOf(info.charAt(i))==1)
        {
            return (true);
        }
     }
     return(false);
}

window.onload = function() {
    if(f1(document.forms[0].elements[0].value,st)==true)
    {
        alert("xyz");
    }
    else
    {
        alert("abc");
    }
}

Open in new window

0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 36496301
working test page : http://jsfiddle.net/vK856/
0
 
LVL 2

Author Closing Comment

by:costaf
ID: 36496470
thx u all
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now