473,326 Members | 2,076 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

javascript functions problem

1
I am having problems trying to insert this function into this piece of code below.


Expand|Select|Wrap|Line Numbers
  1. var pages=['www.lboro.ac.uk:degree programmes','channel4.co.uk', 'www.bbc.co.uk:sports', 'www.skynews.com:the best election']
  2. var w='degree'
  3. var p=0
  4. if(pages[p].indexOf(w)<0)
  5. alert ('not found')
  6. else
  7. alert('found')
i want to use the function find_1(w,p) - to discover if the string w appears in the string pages[p]. Gives an alert of w 'found' or 'not found'. but when i put the function, it doesn't run
Nov 6 '08 #1
7 1164
JosAH
11,448 Expert 8TB
You don't have Java problems, you have Javascript problems; those two languages
are not the same no matter their name similarity. Do you want me to move your
question over to the .NET forum where such questions are answered?

kind regards,

Jos (moderator)
Nov 6 '08 #2
karthickkuchanur
156 100+
whats wrong in it its working fine
Nov 7 '08 #3
gits
5,390 Expert Mod 4TB
what do you mean with 'put the function' ... where do you include/call it?

kind regards
Nov 7 '08 #4
rnd me
427 Expert 256MB
i think you need brackets for else.

thus:

Expand|Select|Wrap|Line Numbers
  1. if(pages[p].indexOf(w)<0)
  2. alert ('not found')
  3. else
  4. alert('found')
should be

Expand|Select|Wrap|Line Numbers
  1. if(pages[p].indexOf(w)<0){
  2.   alert ('not found')
  3. }else{
  4.   alert('found'); 
  5. }
Nov 7 '08 #5
gits
5,390 Expert Mod 4TB
unless there is just one, and only one, statement, the brackets are not strictly required ... but i would even recommend that they are always used since you just have to add them when you want to extend the code later on ... and even use the semicolon to terminate the statements ... its good practice to do so, even when they are not strictly required too :)

kind regards
Nov 7 '08 #6
rnd me
427 Expert 256MB
unless there is just one, and only one, statement, the brackets are not strictly required ... but i would even recommend that they are always used since you just have to add them when you want to extend the code later on ... and even use the semicolon to terminate the statements ... its good practice to do so, even when they are not strictly required too :)

kind regards
touchè.


thanks, its been a couple months since i learned something new about javascript.
also gave me another optimization for my code compressor.
Nov 7 '08 #7
gits
5,390 Expert Mod 4TB
so do you want to 'compress-remove' the brackets, for deployment-versions? quite a nice idea, and certainly worth a look at ... since a lot of brackets and whitespaces could be left out for getting a working script, but its not well readable then ;)

kind regards
Nov 7 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Andy Fish | last post by:
Hi, I want to use an anchor tag to invoke some javascript and I've read that it's bad form to use <a href="javascript:foo()"> I've read endless usenet posts and hint sites on the net, they all...
2
by: GIMME | last post by:
Background ... I've created a web application that allows a user to create an HTML application from IE. The application itself creates an XML representation of a XHTML form. The XHTML...
5
by: elsenraat_76 | last post by:
Hello! I was wondering if someone could help me out with a problem I'm having? I'm trying to input a javascript value into an anchor tag (from a function), but don't have an event to call the...
136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
4
by: Steven | last post by:
Hello, I have 3 files -- 1. mainform.aspx 2. mainform.aspx.cs 3. mouse.js mainform.aspx contains a image button ("zoominimgbut") which will exceute C# code, whenever the user clicks on it....
3
by: useenmelately | last post by:
Hello, I am working with asp.net 2.0 and have run into a problem with the custom validators. The client validation functions were originally written in vbscript, but as this is not compatible...
8
by: Frank | last post by:
Hi, I am working with VS.NET 2005 Ultimately, I wish to call a JavaScript function from a .js file
76
by: lorlarz | last post by:
Crockford's JavaScript, The Good Parts (a book review). This shall perhaps be the world's shortest book review (for one of the world's shortests books). I like Douglas Crockford (because I am a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.