473,378 Members | 1,133 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.

Change form fields by choosing a drop-down option

Hi there

I have been sitting with this for a while now and can't seem to get the correct script online. I get a lot of scripts being able to change a line of text, or input field by selecting an option in a drop-down box.

What i want is to be able to select an option from a drop-down box, which then changes a whole fieldset of 3 or more form field options, depending on the option chosen in the list.

Can anyone help with something like this??
Jan 16 '08 #1
7 2122
acoder
16,027 Expert Mod 8TB
Hi

That wouldn't be too difficult. You just need to loop over the elements. Show your HTML code so we can work from that.
Jan 16 '08 #2
Hi there.

Thank you. I apologize for the late reply. I greatly appreciate any help given on this subject. I have been searching in vain.

[HTML]
<tr>
<td class="lefttd">Please provide one of the following</td>
<td>
<select name="id">
<option value="0">Please Select</option>
<option value="1">UK Driving License</option>
<option value="2">UK Passport</option>
<option value="3">Non-UK Passport</option>
<option value="4">I will provide later...</option>
</select>
</td>
</tr>


<!-- This is option One -->

<tr>
<td class="lefttd">UK Driving Licence Number</td>
<td><input type="text" name="UKdrvl" value="" size="30" class="regtext" />
</td>
</tr>


<!-- This is option Two -->

<tr><td colspan="2">UK Passport Number</td></tr>

<tr>
<td colspan="2">
<input type="text" name="UKpass_num1" value="" size="10" onKeyUp="return autoTab(this, 10, event);" maxlength="10" />
<input type="text" name="UKpass_num2" value="" size="3" onKeyUp="return autoTab(this, 3, event);" maxlength="3" />
<input type="text" name="UKpass_num3" value="" size="7" onKeyUp="return autoTab(this, 7, event);" maxlength="7" />
<input type="text" name="UKpass_num4" value="" size="1" onKeyUp="return autoTab(this, 1, event);" maxlength="1" />
<input type="text" name="UKpass_num5" value="" size="7" onKeyUp="return autoTab(this, 7, event);" maxlength="7" />
<input type="text" name="UKpass_num6" value="" size="2" onkeypress="return numeralsOnly(event)" />
<br />
</td>
</tr>


<!-- This is option Three -->

<tr>
<td colspan="2">Non UK Passport Number</td>
</tr>

<tr>
<td colspan="2">
<input type="text" name="nonUKpass_num1" value="" size="9" onKeyUp="return autoTab(this, 9, event);" maxlength="10"/>
<input type="text" name="nonUKpass_num2" value="" size="1" onKeyUp="return autoTab(this, 1, event);" maxlength="1" />
<input type="text" name="nonUKpass_num3" value="" size="3" onKeyUp="return autoTab(this, 3, event);" maxlength="3" />
<input type="text" name="nonUKpass_num4" value="" size="7" onKeyUp="return autoTab(this, 7, event);" maxlength="7"/>
<input type="text" name="nonUKpass_num5" value="" size="1" onKeyUp="return autoTab(this, 1, event);" maxlength="1" />
<input type="text" name="nonUKpass_num6" value="" size="7" onKeyUp="return autoTab(this, 7, event);" maxlength="7" />
<input type="text" name="nonUKpass_num7" value="" size="13" onKeyUp="return autoTab(this, 13, event);" maxlength="13" />
<input type="text" name="nonUKpass_num8" value="" size="1" onKeyUp="return autoTab(this, 1, event);" maxlength="1" />
<input type="text" name="nonUKpass_num9" value="" size="1"/>

</td>
</tr>
[/HTML]
Jan 21 '08 #3
acoder
16,027 Expert Mod 8TB
When you say that it changes a fieldset, do you mean that these fields should be hidden and only appear when the corresponding option is chosen from the select drop-down?

To hide the fields, add a style="display:none;" to the parent container. To make them visible, change the style to "display:block".
Jan 21 '08 #4
Yes, if they all should be hidden, only if you select an option from the drop down box should the corresponding form options appear below.I get the display:none and display:block, what I don't know how to do is to change the options without reloading the page...

When you say that it changes a fieldset, do you mean that these fields should be hidden and only appear when the corresponding option is chosen from the select drop-down?

To hide the fields, add a style="display:none;" to the parent container. To make them visible, change the style to "display:block".
Jan 21 '08 #5
acoder
16,027 Expert Mod 8TB
I assume you know that you need to use an onchange event handler for the select drop-down element.

To show a row, you will need to access it, so give each row to be shown/hidden an id, then to show it, use document.getElementById(rowID).style.display = 'block';
Jan 21 '08 #6
That much I have gathered yes. I am not a Javascript fundy, and have been struggling to get my code to work in the frameworks available on the net for this kind of thing. I was hoping someone can assist with coding this for me.
Jan 21 '08 #7
acoder
16,027 Expert Mod 8TB
Since you have more than one row for some options, it makes it a little more difficult. In some browsers, you can give a name to each row and access using getElementsByTagName, but this doesn't work in all browsers.

You can set a class for each row, but there's no getElementsByClassName. However, it's easy to get each row using table.getElementsByTagName("tr") :
Expand|Select|Wrap|Line Numbers
  1. var table = document.getElementById("tableID");
  2. rows = table.getElementsByTagName("tr");
  3. for (i = 0; i < rows.length; i++) {
  4.   if (rows[i].className == ("option"+val)) { // assuming class is "option1", "option2", etc.
  5.     rows[i].style.display = 'block';
  6.   } else {
  7.       rows[i].style.display = 'none';
  8.     }
  9. }
Jan 21 '08 #8

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

Similar topics

3
by: Adam | last post by:
Hey guys, I've decided to stop banging my head against the wall and just ask you guys for the answer. I can't seem to find it. I have a form in which I have multiple submit buttons; only, I'm...
2
by: iam247 | last post by:
Hi I have an ASP form which only includes an option list. The list is dynamically created but includes a default value, which is an instruction "Select a group". The code is shown at bottom....
2
by: Galina | last post by:
Hello I have an application in MS Access 2000. I have a form, which includes a subform. The subform is based on a table, but locked for any editing. There is Edit button. When clicked, it starts a...
11
by: ian.davies52 | last post by:
Is there anything I can do about the apparent limit on the number of textboxes that have calculations as their control source on a form or report in ms-access? I have a query that pulls together...
10
by: Tom | last post by:
I am looking for some ideas for how to design the layout of the form for data entry and to display the data for the following situation: There are many sales associates. A sales associate can work...
6
by: Aaron Smith | last post by:
Ok. I have a dataset that has multiple tables in it. In one of the child tables, I have a column that I added to the DataSet (Not in the DataSource). This column does not need to be stored in the...
2
by: dbuchanan | last post by:
Hello, Windows forms & database What are the considerations when choosing how to display reference information from the calling form? What is recommended? Table1 is the parent of Table2. ...
8
by: cwhite | last post by:
i want to create a form where the user can choose from a list of names in table A associated with this name is a telephone and address on the form there will be a drop list for the name,...
5
by: aharding | last post by:
I would like to autopopulate fields in a form by choosing one value from a table and having the corresponding data filled in based on 'Library' tables I have made. I have been successful in building...
8
by: mlwerth | last post by:
Dear Access Group: This is the most basic and most embarrassing of questions, but I cannot find where to change the data type of a text field that I have in Access 2003 to a number field. I've...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...

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.