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

[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.
Expand|Select|Wrap|Line Numbers
  1. <select name="AorB" >
  2. <option value="" selected="selected">Select...</option>
  3. <option value="A" >Option A</option>
  4. <option value="B" >Option B</option>
  5. </select>
I'm already using this way of javascript (Error Alerts):

Expand|Select|Wrap|Line Numbers
  1. <SCRIPT language=JavaScript>
  2. <!--
  3. function check(form) {
  4. if (form.Password.value == "")
  5. { alert("Please enter your Password."); form.Password.focus(); return;}
  6. if (form.Password.value.length < 8)
  7. { alert("Please enter a valid Password."); form.Password.focus(); return;}
  8. form.submit()
  9. }
  10. //-->
  11. </SCRIPT>
Nov 7 '12 #1

✓ answered by Rabbit

This is how you use the on change event.
Expand|Select|Wrap|Line Numbers
  1. <select name="someName" onchange="someFunction()">
Then you just need to write whatever function you need. In this case, you will write one to change the visibility of the <input>s you want to show depending on what they've chosen.

10 1654
P.S: I don't want to make complications when they choose A to get B option javascripts.
Nov 7 '12 #2
Rabbit
12,516 Expert Mod 8TB
I'm not sure what you mean. Do you mean you want to populate a different drop down list with those values depending on what is selected? You can use the onchange event to call a javascript function that will add those options to the other drop down list. If you mean something else, then I don't understand what it is that you're looking for.
Nov 7 '12 #3
Hi Rabbit, thank for your reply, i mean 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.
Nov 7 '12 #4
Rabbit
12,516 Expert Mod 8TB
I still don't understand. What you said is very similar to your original post. Try explaining it a different way. Alternatively, do a mockup and post the image of what you're trying to achieve.
Nov 7 '12 #5
i'm so sorry for ur time, please listen... i will try to explain .... 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:

Expand|Select|Wrap|Line Numbers
  1. <select name="AorB" >
  2. <option value="" selected="selected">Select...</option>
  3. <option value="A" >Option A</option>
  4. <option value="B" >Option B</option>
  5. </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.
Nov 7 '12 #6
Rabbit
12,516 Expert Mod 8TB
By inputs, do you mean actual form elements? <input>? If so, use the on change event to update the visibility property.
Nov 8 '12 #7
Yea i meant <input>-s, how do i use the on change event please ?

I'm currently using this way:

Expand|Select|Wrap|Line Numbers
  1. <SCRIPT language=JavaScript>
  2. <!--
  3. function check(form) {
  4. if (form.Password.value == "")
  5. { alert("Please enter your Password."); form.Password.focus(); return;}
  6. if (form.Password.value.length < 8)
  7. { alert("Please enter a valid Password."); form.Password.focus(); return;}
  8. form.submit()
  9. }
  10. //-->
  11. </SCRIPT>
Nov 8 '12 #8
Please check out this LINK, use view-source too , to understand it..thank you so much once again.
Nov 8 '12 #9
Rabbit
12,516 Expert Mod 8TB
This is how you use the on change event.
Expand|Select|Wrap|Line Numbers
  1. <select name="someName" onchange="someFunction()">
Then you just need to write whatever function you need. In this case, you will write one to change the visibility of the <input>s you want to show depending on what they've chosen.
Nov 8 '12 #10
i fixed it already, thank you so much Rabbit sir, honestly. Cheers.
Nov 8 '12 #11

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

Similar topics

21
by: Stefan Richter | last post by:
Hi, after coding for days on stupid form validations - Like: strings (min / max length), numbers(min / max value), money(min / max value), postcodes(min / max value), telefon numbers, email...
4
by: bnp | last post by:
Hi All, I am quite new the JavaScript. Basically I am a C++ programmer, but now I am working on JavaScript since last 5 days. I have a problem regarding the form validation. I have created a...
9
by: julie.siebel | last post by:
Hello all! As embarrassing as it is to admit this, I've been designing db driven websites using javascript and vbscript for about 6-7 years now, and I am *horrible* at form validation. To be...
7
by: h7qvnk7q001 | last post by:
I'm trying to implement a simple server-side form validation (No Javascript). If the user submits a form with errors, I want to redisplay the same form with the errors highlighted. Once the form...
2
by: FayeC | last post by:
Can anybody point me to a good tutorial/manual on advanced server-side form validation including validation of fields against unwanted strings such as the use of "http://". Thank you in advance,...
27
by: Chris | last post by:
Hi, I have a form for uploading documents and inserting the data into a mysql db. I would like to validate the form. I have tried a couple of Javascript form validation functions, but it...
11
by: Rik | last post by:
Hello guys, now that I'm that I'm working on my first major 'open' forms (with uncontrolled users I mean, not a secure backend-interface), I'd like to add a lot of possibilities to check wether...
5
by: lucyh3h | last post by:
Hi, I am trying to use XMLHttpRequest to do server side validation. I have several fields on a form and a submit button. The submit button has an event assocated with it when clicked. The...
7
ak1dnar
by: ak1dnar | last post by:
Hi, I got this scripts from this URL There is Error when i submit the form. Line: 54 Error: 'document.getElementbyID(....)' is null or not an object What is this error. Complete Files
2
by: munkee | last post by:
Hi all, Basically I have been using form validation incorrectly. Partly because of laziness which I now feel is going to really bite me back if I dont get it sorted. On all of my forms I have a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.