Solved

what is wrong with this code?

Posted on 2011-09-07
4
153 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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. …
In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
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…

829 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