Solved

what is wrong with this code?

Posted on 2011-09-07
4
155 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

737 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