...

View Full Version : [Urgently] Form Validation (If & then)!



closser
11-07-2012, 09:08 PM
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.

<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):


<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.

Fou-Lu
11-07-2012, 09:56 PM
Despite the similar sounding names, Java is not the same as Javascript.
Moving from Java forum to Javascript forum.

closser
11-07-2012, 10:52 PM
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.

Old Pedant
11-07-2012, 11:08 PM
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.

closser
11-07-2012, 11:15 PM
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:


<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.

Old Pedant
11-08-2012, 12:20 AM
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.

closser
11-08-2012, 12:10 PM
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 (http://misinba.altervista.org/form/)

use view-source to view what i included there, thank you so much , once again!

closser
11-08-2012, 03:01 PM
fixed / thank you everyone!

Old Pedant
11-08-2012, 07:42 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum