Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-07-2012, 09:08 PM   PM User | #1
closser
New to the CF scene

 
Join Date: Nov 2012
Posts: 8
Thanks: 1
Thanked 0 Times in 0 Posts
closser is an unknown quantity at this point
Unhappy [Urgently] Form Validation (If & then)!

Hi guys, first i hope u will understand me...
So i want to make a javascript to be shown if somebody chooses option A to show the javascripts for the A1,A2,A3 and if they choose B to show javascripts for the B1,B2,B3. So the A and B it will firstly asked as options from a <select> tag
eg.
Code:
<select name="AorB" >
<option value="" selected="selected">Select...</option>
<option value="A" >Option A</option>
<option value="B" >Option B</option>
</select>
I'm using this way of javascript (Error Alerts):

Code:
<SCRIPT language=JavaScript>
<!--
function check(form) {
if (form.Password.value == "")
{ alert("Please enter your Password."); form.Password.focus(); return;}
if (form.Password.value.length < 8)
{ alert("Please enter a valid Password."); form.Password.focus(); return;}
form.submit()
}
//-->
</SCRIPT>
P.S: I don't want to make complications when they choose A to get B option javascripts or reverse.
closser is offline   Reply With Quote
Old 11-07-2012, 09:56 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,750
Thanks: 4
Thanked 2,468 Times in 2,437 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Despite the similar sounding names, Java is not the same as Javascript.
Moving from Java forum to Javascript forum.
Fou-Lu is offline   Reply With Quote
Old 11-07-2012, 10:52 PM   PM User | #3
closser
New to the CF scene

 
Join Date: Nov 2012
Posts: 8
Thanks: 1
Thanked 0 Times in 0 Posts
closser is an unknown quantity at this point
Ok sorry Fou-Lu, ...btw i hope anybody understood ..... i meant if We select OPTION A there will be shown some Input-s ....and javascript will ask only for the shown input-s so it means OPTION A input-s ... but not to ask for OPTION B input-s too even that they're not shown cause we didnt select OPTION B ... i hope i explained a little for you.
closser is offline   Reply With Quote
Old 11-07-2012, 11:08 PM   PM User | #4
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,556
Thanks: 62
Thanked 4,056 Times in 4,025 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Well, for starters, you have to use the ONCHANGE event of the <select> to change *WHAT* is displayed. That is, to show one or the other set of questions/fields.

Have you done that?

You don't even show what those other questions/fields are in your post.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 11-07-2012, 11:15 PM   PM User | #5
closser
New to the CF scene

 
Join Date: Nov 2012
Posts: 8
Thanks: 1
Thanked 0 Times in 0 Posts
closser is an unknown quantity at this point
Quote:
Originally Posted by Old Pedant View Post
Well, for starters, you have to use the ONCHANGE event of the <select> to change *WHAT* is displayed. That is, to show one or the other set of questions/fields.

Have you done that?

You don't even show what those other questions/fields are in your post.
Hi Old Pedant, thanks for the reply, . i want the javascript to be shown if we don't fill input-s on the form , so the first INPUT (selcet tag) is the main one that includes Option A and Option B, like this:

Code:
<select name="AorB" >
<option value="" selected="selected">Select...</option>
<option value="A" >Option A</option>
<option value="B" >Option B</option>
</select>

Then, once we choose Option B there down will be shown few more input-s (like i said above: B1,B2,B3) , and i want same thing to happen if we choose Option A, so it will show DIFFERENT input-s (A1,A2,A3) , so essence is that i want this javascript to ask for input-s that are shown after choosing an option A or B , but not ask for ALL input-s , only the once that will be shown after selecting an option.
closser is offline   Reply With Quote
Old 11-08-2012, 12:20 AM   PM User | #6
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,556
Thanks: 62
Thanked 4,056 Times in 4,025 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Quote:
Then, once we choose Option B there down will be shown few more input-s (like i said above: B1,B2,B3) ...
Yes, I know. And I wanted you to show us how you will present B1,B2,B3 and what kind of fields they are, etc., etc.

Don't make us create a dummy HTML page for you just to demonstrate this simple code, only to find out that our dummy HTML isn't anything like what you wanted.

Give us the HTML with *ALL* fields (A1,A2,A3 as well as B1,B2,B3) *FIRST* and then it's easier to show you how simple the code is.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 11-08-2012, 12:10 PM   PM User | #7
closser
New to the CF scene

 
Join Date: Nov 2012
Posts: 8
Thanks: 1
Thanked 0 Times in 0 Posts
closser is an unknown quantity at this point
Quote:
Originally Posted by Old Pedant View Post
Yes, I know. And I wanted you to show us how you will present B1,B2,B3 and what kind of fields they are, etc., etc.

Don't make us create a dummy HTML page for you just to demonstrate this simple code, only to find out that our dummy HTML isn't anything like what you wanted.

Give us the HTML with *ALL* fields (A1,A2,A3 as well as B1,B2,B3) *FIRST* and then it's easier to show you how simple the code is.
Hi again, idk if im allowed to send a link, but here is it: LINK

use view-source to view what i included there, thank you so much , once again!
closser is offline   Reply With Quote
Old 11-08-2012, 03:01 PM   PM User | #8
closser
New to the CF scene

 
Join Date: Nov 2012
Posts: 8
Thanks: 1
Thanked 0 Times in 0 Posts
closser is an unknown quantity at this point
fixed / thank you everyone!
closser is offline   Reply With Quote
Old 11-08-2012, 07:42 PM   PM User | #9
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,556
Thanks: 62
Thanked 4,056 Times in 4,025 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Great!

I tried to go to your link, but it just gives a message saying the index page is missing.

If you need more help, post a corrected link. Yes, posting links that show code like that is not only permissible but encourage. You should only get dinged if it was an obvious attempt at advertising or it linked to a site that had, shall we say, improper content.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Reply

Bookmarks

Tags
form javascript

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:04 PM.


Advertisement
Log in to turn off these ads.