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

If Statement help

I need help (I'm a newby and just learning Javascript). I need an if statement for my required Address Fields that would only be required when "Other Address" radio button is selected.

Expand|Select|Wrap|Line Numbers
  1.     var x=document.forms["myForm"]["Addr0"].value
  2.     if (x==null || x=="")
  3.   {
  4.       alert("No/Street must be filled out");
  5.       return false;
  6.   }
  7.     var x=document.forms["myForm"]["Addr1"].value
  8.     if (x==null || x=="")
  9.   {
  10.       alert("Suburb must be filled out");
  11.       return false;
  12.   }
  13.     var x=document.forms["myForm"]["Addr2"].value
  14.     if (x==null || x=="")
  15.   {
  16.       alert("Please Select a State");
  17.       return false; 
  18.   }
  19.     var x=document.forms["myForm"]["Addr3"].value
  20.     if (x==null || x=="")
  21.   {
  22.       alert("Post Code must be filled out");
  23.       return false;
  24.   }
  25. <div id="radBtnCont">
  26.            Home Address: <input type="radio" name="radBtn" value="home" />
  27.             Other Address:<input type="radio" name="radBtn" value="other" /><br /><br />
  28.  
  29.    </div>
  30.         <div id="addressCont">
  31.  
  32. <I><B>If Other Address:</I></B><br /><br />
  33.  
  34.           No/Street:  <input type="text" name="Addr0" />
  35.  
  36.      Suburb: <input type="text" name="Addr1" /><br /><br />
  37.  
  38.     State: <select name="Addr2">
  39.                 <option> Please Select
  40.     <option value="act">ACT</option>
  41.     <option value="nt">NT</option>
  42.                 <option value="nsw">NSW</option>
  43.     <option value="qld" >QLD</option>
  44.     <option value="sa">SA</option>
  45.     <option value="tas">TAS</option>
  46.                 <option value="wa">WA</option></select>
  47.  
  48.     Post Code:<input type="text" name="Addr3" /><br />
  49.                </div><br /><br />
Thanks Joan.
Mar 4 '11 #1
1 1012
Dormilich
8,658 Expert Mod 8TB
in pseudo code
Expand|Select|Wrap|Line Numbers
  1. // I abbreviated HTML elements by <element_description>
  2. if (<other address radio>.checked && !<other address text field>.value)
  3.     error()
PS. (x==null || x=="") is redundant, because a form element’s value is never null and you make a non-typesafe comparison (i.e. x==null fires also when x is false, 0, "" or undefined)
Mar 4 '11 #2

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

Similar topics

4
by: soni29 | last post by:
hi, i have a small question regarding sql, there are two tables that i need to work with on this, one has fields like: Table1: (id, name, street, city, zip, phone, fax, etc...) about 20 more...
2
by: Little PussyCat | last post by:
Hello, I hope you can help me. We have a SQL Server 2000 database at work, (which works with a VB6 frontend) which grew to a considerable size, so one of my past colleagues sent me this...
9
by: Peter | last post by:
My problem is the last bit of coding below, the like statement does not work. what I have is a product options field and in it is stored characters i.e. "avcy" etc what the query does is...
11
by: Scott C. Reynolds | last post by:
In VB6 you could do a SELECT CASE that would evaluate each case for truth and execute those statements, such as: SELECT CASE True case x > y: dosomestuff() case x = 5: dosomestuff() case y >...
2
by: NathanV | last post by:
I need some help with a SQL statement (SQL Server 2k). I have three tables, an Artists table which holds user info, a Types table which holds the TypeID and Description for different types (I.e....
3
by: igendreau | last post by:
I am writing a query that uses a switch statement. Here's my statement: Region: Switch(="PA" Or ="DE","PennDel",="NY" Or ="NJ","Atlantic") Basically I have a new field named "Region". If...
3
by: samearle | last post by:
Help me write this for MS access, I'm used to Oracle - SELECT Users.*, group_1, group_2, group_3 from (select UserInGroup.UserID, max(decode(GroupID, 1, GroupID, null)) as group_1,
3
by: schoultzy | last post by:
Hello everyone, I am working with the following code: select section_master.trm_cde, section_master.crs_cde, crs_title, crs_capacity, crs_enrollment, section_master.udef_3a_1, monday,...
0
by: feeblemind | last post by:
Hi everyone, I am having problem/troubles with creating an sql inline statement for our application. How do I create a statement/query that selects list of servers with defined date ranges, but...
3
by: erik6408 | last post by:
I am trying to use the IIF statement to look for a null value. That seems to be working fine.. The problem occurs when I use a LIKE Statement inside the IIF statement. Here are some examples:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.