473,395 Members | 1,377 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,395 software developers and data experts.

Help Determining Result of Function (true/false)

Hi Guys. I'm hoping someone here knows how to do this.

I have a function, let's say:
Expand|Select|Wrap|Line Numbers
  1. function dosomert()
  2. {
  3. doing some stuff;
  4. return valid;
  5. }
  6.  
Now, as you can see, if all is run then it returns valid. But how do I use an if statement to find out what this particular function has returned?

Like:

Expand|Select|Wrap|Line Numbers
  1. function checkvalid(){
  2. if (function dosomert.returned='valid'){
  3. do something else;}
  4. }
  5.  
Any ideas?

Thanks.
Aug 10 '08 #1
3 1370
Atli
5,058 Expert 4TB
Hi.

Consider this:
Expand|Select|Wrap|Line Numbers
  1. // Create a function to compare something
  2. function compareThings(thing1, thing2) {
  3.   if(thing1 == thing2) {
  4.     return true;
  5.   }
  6.   else {
  7.     return false;
  8.   }
  9. }
  10.  
  11. // Check the thing and print results
  12. var result = compareThings(1, 2);
  13.  
  14. if(result == true) {
  15.   document.write("They match!");
  16. }
  17. else {
  18.   document.write("They don't match!");
  19. }
  20.  
Is this what you are talking about?
Aug 10 '08 #2
Hi.

Consider this:
Expand|Select|Wrap|Line Numbers
  1. // Create a function to compare something
  2. function compareThings(thing1, thing2) {
  3.   if(thing1 == thing2) {
  4.     return true;
  5.   }
  6.   else {
  7.     return false;
  8.   }
  9. }
  10.  
  11. // Check the thing and print results
  12. var result = compareThings(1, 2);
  13.  
  14. if(result == true) {
  15.   document.write("They match!");
  16. }
  17. else {
  18.   document.write("They don't match!");
  19. }
  20.  
Is this what you are talking about?
OMG, that is exactly what I was talking about. My mistake was not putting the result of the function in a variable. That did the trick.

Thank you so much for your time!
Aug 10 '08 #3
Atli
5,058 Expert 4TB
OMG, that is exactly what I was talking about. My mistake was not putting the result of the function in a variable. That did the trick.

Thank you so much for your time!
Actually, putting it in a variable isn't really needed either. Although, if you plan on using the returned value more than once, it's best to put it into a variable.

You could just do:
Expand|Select|Wrap|Line Numbers
  1. if( compareThings(1, 2) ) {
  2.   document.write("Match!");
  3. } else {
  4.   document.write("No match");
  5. }
  6.  
The compiler will basically replace the function call with the value it returns.
Aug 10 '08 #4

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

Similar topics

2
by: wrrn | last post by:
Hi - I'm beginning work on an existing web site which was created with Adobe Golive. The page in question has CSACTIONS which is part of Golive's CyberStudio. Anyway, the code below has this...
1
by: MDBloemker | last post by:
can anyone help me fathom out how to use this bit of code: Public Class Utilities Public Shared Sub CreateConfirmBox(ByRef txt As WebControls.TextBox, _ ByVal strMessage As String)...
7
by: Aaron | last post by:
Complete code follows. I am new to .NET programming (and programming in general) and I am having a difficult time understanding how to fill a variable in one sub, and then access it from...
5
by: Learner | last post by:
Hello, Here is the code snippet I got strucked at. I am unable to convert the below line of code to its equavalent vb.net code. could some one please help me with this? static public...
7
by: Siv | last post by:
Hi, I have a stored procedure that I want to execute and then wait in a loop showing a timer whilst it completes and then carry on once I get notification that it has completed. The main reason...
25
by: crescent_au | last post by:
Hi all, I've written a login/logout code. It does what it's supposed to do but the problem is when I logout and press browser's back button (in Firefox), I get to the last login page. In IE,...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
2
by: muchexie | last post by:
i have two scripts that are not running to reset a password that has been forgotten and the other to change old password. here are the scripts. change_passwd.php session_start();...
16
by: gnawz | last post by:
I have a pagination function I am using in a file called functions.php as below<? //Pagination functions function getPagingQuery($sql, $itemPerPage = 10) { if (isset($_GET) && (int)$_GET > 0) ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.