473,785 Members | 3,142 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

a matter of logic?!

Hello,

I am not getting the logic right here...

I want to send to a php file the results of clicking some buttons but
only when an email address has been added, so

function checkBeforeSend (){

if (not all questions answered) {
alert("complete all questions");
} else if (no email added) {
alert ("add email address");
} else {
send();
}

}

something wrong here - ideas please!

Cheers

Geoff

Mar 24 '08 #1
3 1265
Geoff Cox wrote on 24 mrt 2008 in comp.lang.javas cript:
Hello,

I am not getting the logic right here...

I want to send to a php file the results of clicking some buttons but
only when an email address has been added, so

function checkBeforeSend (){

if (not all questions answered) {
alert("complete all questions");
} else if (no email added) {
alert ("add email address");
} else {
send();
}

}

something wrong here - ideas please!
Logically nothing is wrong.
The {} are superfluous, or there are two missing.

The last else "belongs to the last if, btw.
Javascript has no elssif like vbscript,
so write these keywords on seperate lines.
Good logical indenting will show you:

function checkBeforeSend (){
if (! allQuestionsAns wered)
alert("complete all questions")
else
if (! emailAdded)
alert ("add email address")
else
send();
};

But if you want complete {} do it this way:

function checkBeforeSend (){
if (! allQuestionsAns wered) {
alert("complete all questions");
}
else { // this { you missed
if (! emailAdded) {
alert ("add email address");
}
else {
send();
};
}; // and this corresponding closing }
};

Another way is by exchangeing the else clauses for early return clauses,
this is perhaps easier to do and to maintain:

function checkBeforeSend (){
if (! allQuestionsAns wered) {
alert("complete all questions");
return;
};
if (! emailAdded) {
alert ("add email address");
return;
};
send();
};

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Mar 25 '08 #2
On 25 Mar 2008 00:11:06 GMT, "Evertjan."
<ex************ **@interxnl.net wrote:

>But if you want complete {} do it this way:

function checkBeforeSend (){
if (! allQuestionsAns wered) {
alert("complete all questions");
}
else { // this { you missed
if (! emailAdded) {
alert ("add email address");
}
else {
send();
};
}; // and this corresponding closing }
};
Thanks Evertjan,

Ive used the above and it works fine if all the questions are answered
and the email address is entered.

But! If the questions are all answered but the email address is not
entered I get the warning to add an email address but the send()
results do not appear. (I'm using AJAX.Updater for this)

To call the checkBeforeSend (() I use

<button onclick = "checkBeforeSen d();">Click here to see if you were
right!</button>

I can get the results by clicking on this button once the email
address has been added but I would like the data to be sent after
entering the email address without needing to go back to the button.

Can you see the answer without having all the code?!

Cheers

Geoff
Mar 25 '08 #3
Geoff Cox wrote:
<snip>
Ive used the above and it works fine if all the questions
are answered and the email address is entered.

But! If the questions are all answered but the email address
is not entered I get the warning to add an email address but
the send() results do not appear.
Isn't that what you specified and programmed it to do?
(I'm using AJAX.Updater for this)
That means nothing without context. All you are saying here is that you
are using a property accessor, nothing about what property of what
object is being accessed, or how it is being used.
To call the checkBeforeSend (() I use

<button onclick = "checkBeforeSen d();">Click here to see
if you were right!</button>
BUTTON elements without TYPE attributes are problematic because the
official default TYPE is 'submit' but IE defaults the type to 'button',
so you get inconsistent behaviour between browsers if you do not specify
a TYPE.
I can get the results by clicking on this button once
the email address has been added but I would like the
data to be sent after entering the email address without
needing to go back to the button.
That does not sound like a friendly UI (submitting an e-mail address
before the user has a chance to notice and fix their typo).
Can you see the answer without having all the code?!
Can you see without light?

Richard.
Mar 25 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

250
10482
by: Sugapablo | last post by:
Just out of curiosity, while checking on a site I was working on, I decided to throw a couple of the web's most popular URLs into the W3C Markup Validator. Out of microsoft.com, google.com, amazon.com, yahoo.com, aol.com, and mozilla.org, only Mozilla's site came back "Valid HTML". So if all these places, with their teams of web developers don't seem to care, should the rest of us small time web devs concern ourselves with standards?...
0
1214
by: Al Fatykhov | last post by:
Using MABLE logic engine with existing .NET applications. MABLE web services provide an interface to MABLE business objects and logic. Let us review some technical details of the MABLE web services. · MABLE utilizes SOAP 1.2 protocol. · MABLE uses AXIS 1.4 as a web service transport. · MABLE support state-full conversations by implementing a conversation session.
0
1913
by: Wim Vanhoof | last post by:
----------------------------------------------------------- WLPE' 06 - CALL FOR PAPERS Workshop on Logic-based Methods in Programming Environments (satellite workshop of ICLP’06) August 16, 2006
66
3644
by: Johan Tibell | last post by:
I've written a piece of code that uses sockets a lot (I know that sockets aren't portable C, this is not a question about sockets per se). Much of my code ended up looking like this: if (function(socket, args) == -1) { perror("function"); exit(EXIT_FAILURE); } I feel that the ifs destroy the readability of my code. Would it be
0
1591
by: fiona | last post by:
FOR IMMEDIATE RELEASE Catalyst release low cost logic processing tool 87% of defects in software are errors in logic Yucca Valley, CA, September 2006 - Catalyst Development Corporation, publisher of SocketWrench and SocketTools, today announced the release of its first application software, a logic processing software tool. LogicGem is designed to provide a familiar, easy-to-use way to create,
14
3571
by: rabbitrun | last post by:
Hi Everyone, I work for a financial company. I am planning to give a presentation to rest of the development team (15 people) here on moving server side logic to client-side javascript for an internal intranet application rewrite. This approach will definitely stir up hot debate from hardcore server-side Java folks who wants to do UI stuff even on the server!. Since I am pretty much known as the JS or UI Guy of the group, my Boss...
1
1281
by: dr | last post by:
does anyone see what is wrong with my .gif download logic? no matter what image url i try it downloads a junk file that can't be opened in any paint program. System.Net.WebRequest myRequest = System.Net.WebRequest.Create(url); System.Net.WebResponse myResponse = myRequest.GetResponse(); System.IO.Stream imgStream = myResponse.GetResponseStream(); long len = myResponse.ContentLength; byte binarydata = new byte;
9
2743
by: SAL | last post by:
Hello, I have a Dataset that I have table adapters in I designed using the designer (DataLayer). I have a business logic layer that immulates the DataLayer which may/may not have additional logic in. My business classes are, of course, decorated with the: <System.ComponentModel.DataObject() attribute. So, I drop a GridView on a webform and set its datasource to an ObjectDatasource which in turn is using one of my business logic...
15
2433
by: bruno.desthuilliers | last post by:
On 27 juin, 18:09, "John Salerno" <johnj...@NOSPAMgmail.comwrote: For which definitions of "content" and "logic" ??? The point of mvc is to keep domain logic separated from presentation logic, not to remove logic from presentation (which just couldn't work). Templating systems are for presentation logic. Whether they work by embedding an existing complete programmation language or by providing they're own specialised mini-language (or...
0
9645
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10325
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10148
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10091
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9950
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3646
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.