• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 194
  • Last Modified:

Make one field mandatory if another field has certain text in it

Hi all.

Not sure where this belongs So thought i'll put it here.

I need to make a field madatory only if a certain response has been made in another field. ie,

Field1 has three options (Mandatory)

Option1
Option2
Option3

Field2 (Will be email or Number).

If someone choses option one, it inserts the text into the database
If option2 is chosen, then a email address is needed
If option3 is chosen, then a number is required.

The system i use is Dreamweaver for my madnatory fields selection normally and code is ASP VBScript.

Any help would be appreciated.

Baker
0
Bakersville
Asked:
Bakersville
1 Solution
 
inviserCommented:
This should give you an idea of how this can be done:

<form name="form" method="post" action="">

<select name="field1" onchange="updateForm()">
<option>Option1</option>
<option>Option2</option>
<option>Option3</option>
</select>

<div id="field2" style="display: none">
<span id="field2Text"></span>&nbsp;<input type="text" name="field2">
</div>

<script language="javascript">
function updateForm(field1) {
    var field1 = document.form.field1.options[document.form.field1.selectedIndex].text;


    if (field1 == "Option1") {
        document.getElementById("field2").style.display = "none";
    }
    else if (field1 == "Option2") {
        document.getElementById("field2").style.display = "inline";
        document.getElementById("field2Text").innerHTML = "email";
    }
    else if (field1 == "Option3") {
        document.getElementById("field2").style.display = "inline";
        document.getElementById("field2Text").innerHTML = "number";
    }    
}
</script>
0
 
BakersvilleAuthor Commented:
Hi inviser

thank you for yu response.  I am on Hols at the moment and will give it a try once i return in a week monday.  

thanks

Baker
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now