473,837 Members | 1,541 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Pass variable selected from drop down option field to text fields

Dan
Can anyone offer suggestions on how to do this or if it is possible?

I have a form that uses a drop down box and 2 text fields.

What I am trying to do is have the value of each text box set by the
choice from the drop down box.

Something like:

<form name="populatef rm" id="contactfrm " method="post"
action="results .asp">

<select name="region" size="10">
<option value="Choice 1" JavaScript "SET Text Box 1 to 12:00; SET Text
Box 2 to 5:00">Choice 1</option>
<option value="Choice 2" JavaScript "SET Text Box 2 to 5:00; SET Text
Box 1 to 11:00">Choice 2</option>
</select>
<P>
<input type="text" name="text_box_ 1" value="value from drop down box
script" size="5"><BR>
<input type="text" name="text_box_ 2" value="value from drop down box
script" size="5"><BR>

<input type="submit" value="Submit">
</form>
This is related to the time question I asked below. I've searched the
web and can't find exactly what I am looking for.

Thanks, Dan
Jul 23 '05 #1
4 6319
Dan wrote:
What I am trying to do is have the value of each text box set by the
choice from the drop down box.

Something like:

<form name="populatef rm" id="contactfrm " method="post"
action="results .asp">

<form ...>
<select name="region" onchange
="this.form['text_box_'+(th is.selectedInde x+1)].value
=this[this.selectedIn dex].value">
<option value="5.00" >Choice 1</option>
<option value="11.00">C hoice 2</option>
<input type="text" name="text_box_ 1"size="5">< BR>
<input type="text" name="text_box_ 2" size="5">
</select>
</form>

Mick
Jul 23 '05 #2
Dan
Thank you for posting the script, I think my
question wasn't clear. I tried modifing the posted script but I'm
missing something.

What I would like to do is have the drop down
selection keeps it defined variable that is passed on
to database. Depending on which value from the drop
down box is selected, it will populate 2 different
text boxes with 2 different values.

Thanks for any help!

Here is the script:

<SCRIPT LANGUAGE="JavaS cript">

var firstArray = new Array("('Select region','',true ,true)",

//
Each field below will have 2 different time values
that will be added to the 2 text boxes.
//

"('this value selected and sent to script on submit'
value_1_for_tex t_box_1=5:00;
value_2_for_tex t_box_2=12:00;) ",
"('Highway 1' value_1_for_tex t_box_1=11:00;
value_2_for_tex t_box_2=1:00;)" ,
"('Highway 2' value_1_for_tex t_box_1=7:00;
value_2_for_tex t_box_2=4:00;)" ,
"('highway 3' value_1_for_tex t_box_1=8:00;
value_2_for_tex t_box_2=22:00;) ",
"('etc. for about 6 more locations')");
var secondArray = new Array("('Select region','',true ,true)",
"('highway 4' value_1_for_tex t_box_1=3:00;
value_2_for_tex t_box_2=6:00;)" ,
"('highway 5'value_1_for_t ext_box_1=5:00;
value_2_for_tex t_box_2=17:00;) ",
"('etc. for about 6 more locations')");
function populateLocatio n(inForm,select ed) {
var selectedArray = eval(selected + "Array");

for (var i=0; i < selectedArray.l ength; i++) {
eval("inForm.lo cation.options[i]=" + "new Option" +
selectedArray[i]);
}
}
</script>

<script type="text/javascript">
function addTimes(a,b,c) {
if (a.value != '') {
/* Validate input here to check time entered is
of correct hh:mm format and within required
range
Handle error if is isn't
*/
}
var t0 = a.value.split(' :');
var t1 = b.value.split(' :');
var t2 = c.value.split(' :');

var m1 = +t0[1] + +t1[1];
var h1 = +t0[0] + +t1[0] + Math.floor(m1/60);
m1 = (m1 % 60);
b.value = h1 + ':' + m1;

var m2 = +t0[1] + +t2[1];
var h2 = +t0[0] + +t2[0] + Math.floor(m2/60);
m2 = (m2 % 60);
c.value = h2 + ':' + m2;
}
</script>
</head>

<body>

<form method="POST" action="results .asp" name="loc">

//Below is the value that needs to be passed on to the
ASP form. The value selected below will load a 2nd
drop down list that will contain the two variables for
the text boxes.
//

<select name="region"
onChange="popul ateLocation(doc ument.loc,docum ent.loc.region. options[document.loc.re gion.selectedIn dex].value)">
<option selected value=''>Select Region</option>
<option value='Region1' >Region1</option>
<option value='Region2' >Region2</option>
</select>

//The drop down list below is populated by the 1st
drop down list script and contains 1 variable that is
passed to the Data Base and contains the two variables
that need to be added to the 2 text boxes.
//

<select name="location" >
<option value=''>Choose Region 1st</option>
</select>
<input type="text" name="location_ 1"
size="20"></font>
<label for="inTime">
<input type="text" name="inTime"
onblur="addTime s(this,this.for m.time1,
this.form.time2 )"></label>

//The time value is inserted below from your script
using values from the second set of drop down boxes.
//

<input type="text" name="time1"
value="this is the part I am trying to script1"></label>

//The 2nd time value is inserted below from your
script using values from the second set of drop down
boxes.
//

<label for="inTime"><i nput type="text"
name="time2" value="this is the part I am trying to script2"></label>

<input type="submit" value="Submit" name="B1">
<input type="reset" value="Reset" name="B2">
</form>
Mick White <mw***********@ rochester.rr.co m> wrote in message news:<Ge******* **********@twis ter.nyroc.rr.co m>...
Dan wrote:
What I am trying to do is have the value of each text box set by the
choice from the drop down box.

Something like:

<form name="populatef rm" id="contactfrm " method="post"
action="results .asp">

<form ...>
<select name="region" onchange
="this.form['text_box_'+(th is.selectedInde x+1)].value
=this[this.selectedIn dex].value">
<option value="5.00" >Choice 1</option>
<option value="11.00">C hoice 2</option>
<input type="text" name="text_box_ 1"size="5">< BR>
<input type="text" name="text_box_ 2" size="5">
</select>
</form>

Mick

Jul 23 '05 #3
Dan
I'm making some progress.

I can't seem to get this to take more than 1 variable. High_Way2 will
not pass on its time value.

Anyone see any glaring errors?

Thanks again for all the help.

<script language="JavaS cript">
<!--

function Trip_Time(Traff ic_Results) {
if (document.Traff ic_Results.CIP_ Diff.value == "High_Way1" ) {
document.Traffi c_Results.displ ay_time.value = "2:20";

if (document.Traff ic_Results.CIP_ Diff.value == "High_Way1" ) {
document.Traffi c_Results.displ ay_time2.value = "4:30";

if (document.Traff ic_Results.CIP_ Diff.value == "High_Way2" ) {
document.Traffi c_Results.displ ay_time.value = "2:20";

if (document.Traff ic_Results.CIP_ Diff.value == "High_Way2" ) {
document.Traffi c_Results.displ ay_time2.value = "4:30";

}

}
}

}
else {
document.Traffi c_Results.displ ay_time.value = "0:00";

document.Traffi c_Results.displ ay_time2.value = "0:00";

}
}

// -->
</SCRIPT>
</HEAD>

<BODY BGCOLOR="white" >

<form name="Traffic_R esults">
<select name="CIP_Diff" onChange="Trip_ Time()">
<option value="choose" selected>Choose </option>
<option value="High_Way 1">High Way 1</option>
<option value="High_Way 2">High Way 2</option>

</select>&nbsp;&n bsp;&nbsp; <font size="-1">Starting Location</font>
<BR>

Time at Location <input type=text name="reported_ time" size=5
value=""><br>
ETA 1 <input type=text name="display_t ime" size=5 value="0:00"><b r>
ETA 2 <input type=text name="display_t ime2" size=5 value="0:00">

</form>
Jul 23 '05 #4
do****@rocketma il.com (Dan) wrote in message news:<29******* *************** ****@posting.go ogle.com>...
I'm making some progress.

I can't seem to get this to take more than 1 variable. High_Way2 will
not pass on its time value.

Anyone see any glaring errors?

Thanks again for all the help.

<script language="JavaS cript">
<!--

function Trip_Time(Traff ic_Results) {
if (document.Traff ic_Results.CIP_ Diff.value == "High_Way1" ) {
document.Traffi c_Results.displ ay_time.value = "2:20";

if (document.Traff ic_Results.CIP_ Diff.value == "High_Way1" ) {
document.Traffi c_Results.displ ay_time2.value = "4:30";

if (document.Traff ic_Results.CIP_ Diff.value == "High_Way2" ) {
document.Traffi c_Results.displ ay_time.value = "2:20";

if (document.Traff ic_Results.CIP_ Diff.value == "High_Way2" ) {
document.Traffi c_Results.displ ay_time2.value = "4:30";

}

}
}

}
else {
document.Traffi c_Results.displ ay_time.value = "0:00";

document.Traffi c_Results.displ ay_time2.value = "0:00";

}
}

// -->
</SCRIPT>
</HEAD>

<BODY BGCOLOR="white" >

<form name="Traffic_R esults">
<select name="CIP_Diff" onChange="Trip_ Time()">
<option value="choose" selected>Choose </option>
<option value="High_Way 1">High Way 1</option>
<option value="High_Way 2">High Way 2</option>

</select>&nbsp;&n bsp;&nbsp; <font size="-1">Starting Location</font>
<BR>

Time at Location <input type=text name="reported_ time" size=5
value=""><br>
ETA 1 <input type=text name="display_t ime" size=5 value="0:00"><b r>
ETA 2 <input type=text name="display_t ime2" size=5 value="0:00">

</form>


You've posted so much conflicting code, hard to even guess at what
you're doing. In these instances, it's usually best to post some
(valid) HTML, with a simple description of what needs to happen.

Store the data in an object/array (same thing, really) and use the
selected option value as a 'key' to extract & process it.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>untitled </title>
<script type="text/javascript">
//<![CDATA[

var data = new Object;
data['High_Way1'] = '2:20|4:30';
data['High_Way2'] = '3:40|5:15';
data['default'] = '0:00|0:00';

function trip_time(selOb j)
{
var sval = selObj.options[selObj.selected Index].value, //get selected
value
els = selObj.form.ele ments, //form elements
separator = '|', //separates data (above)
d = data[sval || 'default'].split(separato r); //so, split it into an
array
els.display_tim e.value = d[0]; //output 1st element
els.display_tim e2.value = d[1]; //output 2nd element
}

//]]>
</script>
</head>
<body>
<form name="Traffic_R esults">
<select name="CIP_Diff" onchange="retur n trip_time(this) ">
<option value="" selected="selec ted">Choose</option>
<option value=""></option>
<option value="High_Way 1">High Way 1</option>
<option value="High_Way 2">High Way 2</option>
</select>
&nbsp;&nbsp;&nb sp; <font size="-1">Starting Location</font>
<br />
Time at Location <input type="text" name="reported_ time" value=""
size="5" />
<br />
ETA 1 <input type="text" name="display_t ime" value="0:00" size="5"><br
/>
ETA 2 <input type="text" name="display_t ime2" value="0:00" size="5" />
</form>
</body>
</html>
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
10268
by: Lisa | last post by:
I have a drop down that defaults to "select" after the page refreshes. How do I keep the selected value in the dropdown field... I've tried EVERYTHING and nothing works! :( <script LANGUAGE="JavaScript"> function getServer(form){ var cdoServerName = document.frmSoftware.cdoServerName.options.value;
11
2509
by: Dan | last post by:
Hello all, I am getting records from a db and displaying the records to the user through a drop down menu in an asp page. Each record has 6 fields and I need to display them all to the user in the drop down. The problem is that the fields contain values of all different lengths and the columns are not aligned.
2
1682
by: Dan | last post by:
Here is the working script if anyone is interested. I was missing the else if. <script language="JavaScript"> <!-- function Trip_Time(Traffic_Results) { if (document.Traffic_Results.CIP_Diff.value == "point1") { document.Traffic_Results.display_time.value = "2:20";
19
9094
by: nazgulero | last post by:
Hello all, I wonder if anybody can give me a hint about what I have to do to get this working: I am creating a drop down box using the script below. The result is two text fields; now I want to pass those values, which come from the drop down box, to the next page. The next page should then simply look like this:
3
2998
by: John Walker | last post by:
Hi, On an ASP.NET page I have a drop down list control. When the user pulls down the list and makes a selection, I perform validation, and if the validation fails I want the selected item in the drop down box to go back to what the value was before the user tried to change it, but at that point I will not know what the original value was. Or is there a drop down control "revert" method, or is there any way of knowing what the original...
2
8637
by: clickon | last post by:
I am using ASP.net 2.0 and trying to take advantage of the updated data editing facilities provided through the SQLDataSource control and the DetailsView control. The data is a record from a customer complaints table and one of the fields on the DetailsView control is called ComplaintType. The field is a template field and in insert mode and edit mode i have used a DropDownList control bound to a set of keys and values in a ComplaintTypes...
0
2932
by: Jeremy Wallace | last post by:
Folks, Here's a write-up I did for our developer wiki. I don't know if the whole rest of the world has already figured out how to do this, but I hadn't ever seen it implemented, and had spent a lot of time trying to figure it out, over the years. It finally dawned on me a couple of weeks ago how to do this. A couple of notes: 1) This is written for a different audience than CDMA; it's written for
4
2524
by: coldfusionstudent | last post by:
i wish to show/appear and dissappear text box based on a the drop down item selected. what do i have to add? thanks under Comm_DEV drop down selection.
1
5085
by: sparksol | last post by:
I have a form with a drop down box. If you select an option in the drop down box (depending which option is selected) one or two textbox(es) and a submit button display. I would like to keep the textbox(es) and the submit button showing until another option is selected. Also the data that's submitted is showing on the form page. Here's an example - I need the code below to do this: 1. I go to the page - I see a drop down box. 2. I...
0
9843
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9683
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10577
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10630
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9407
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7811
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5670
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5851
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4476
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.