Time:
Scotland: Sat, 12:47 am
Rhode Island: Fri, 7:47 pm
Florida: Fri, 7:47 pm
New Mexico: Fri, 5:47 pm
California: Fri, 4:47 pm

Click here to visit Livelife365.com

Click here to visit nmdarts.com



Buy this Ad Space.

180px wide.

Please get in touch with KH@ if you are interested and make an offer.

CLICK HERE TO GET AUCTION BAR NOW
US$10 per year - Save $100s!
The Fabulously Unfair
WebX Auction Bar. For Ebay etc.
Ro-Sham-Bo the opposition. Laugh like Eric Cartman when you win! CLICK HERE NOW!


More information and sign-up.

WebXpertz Hosting.
Custom fit from $5pm. PHP/MySQL
You'll save money, we'll save money. Seems fair to me. Interested? If so Please PM me here and tell me what you need. Thanks!


Please click here for more information

For continued disscussion on this topic : Passing values on forms


ecojohnson
06-23-2001, 12:57 AM
I am struggling to figure out how to pass values from an item into multiple text fields.

Specifically, what I am trying to do is set up my form so that when a user clicks on an item in one of the selectboxes, all the properties of the selected item will appear dynamically in the appropriate text boxes. If they select on another item, property values of the newly selected item will replace those old values (does this make sense?). I can easily do this with one text box. Where I run into problems is when I try to populate more than one text box with the select value's properites.

Any help is much appreciated.

<CFQUERY NAME="qNamePick">
SELECT ID, FName, LName, Address, City, Zip, Phone, Description
FROM NameTable
</CFQUERY>

<body>
<center>
<FORM ACTION="form2" METHOD="post" NAME="Dsp_Sel_Project" ID="Dsp_Sel_Project">
<TABLE>
<TD>
<SELECT NAME="ProjectNameList" ID="ProjectNameList" SIZE="5" style="width:225" onChange="parent.passText(this.form.ProjectNameList.options[this.form.ProjectNameList.selectedIndex].value);">
<OPTION VALUE="New">New...</OPTION>
<CFOUTPUT QUERY="qNamePick">
<OPTION VALUE="#qNamePick.name#">#qNamePick.name#</OPTION>
</CFOUTPUT>
</SELECT>
</TD>
<TD>

</TD>
<TD>
<SELECT NAME="ProjectAddressList" ID="ProjectAddressList" SIZE="5" style="width:225" onChange="parent.passText(this.form.ProjectAddressList.options[this.form.ProjectAddressList.selectedIndex].value);">
<OPTION VALUE="New">New...</OPTION>
<CFOUTPUT QUERY="qNamePick">
<OPTION VALUE="#qNamePick.Address#">#qNamePick.Address#</OPTION>
</CFOUTPUT>
</SELECT>
</TD>
</TR>
</TABLE>
<TABLE>
<TR>
<TD>FName</TD>
<TD><INPUT TYPE="text" NAME="test1" MAXLENGTH="50"></TD>
<TD>LName</TD>
<TD><INPUT TYPE="text" NAME="test2" MAXLENGTH="50"></TD>
</TR>
<TR>
<TD>Address</TD>
<TD><INPUT TYPE="text"></TD>
<TD>City</TD>
<TD><INPUT TYPE="text"></TD>
</TR>
<TR>
<TD>Zip</TD>
<TD><INPUT TYPE="text"></TD>
<TD>Phone</TD>
<TD><INPUT TYPE="text"></TD>
</TR>
</TABLE>
<TABLE>
<TR>
<TD>Description</TD>
<TD><INPUT TYPE="text" STYLE="width:388"></TD>
</TR>
</TABLE>

<INPUT TYPE="submit" VALUE="Continue">
<INPUT TYPE="submit" VALUE=" Save ">
<INPUT TYPE="Reset" Value=" Clear ">
</FORM>

Jesuisiosono
06-23-2001, 01:40 AM
Hi ecojohnson,

I think I understand what you want.
What you want is something like this:


function fillThem()
for (i = 0; i < numOfField2Fill ; i++)
{
document.formName.elements[i].value = datasetField[i];
}


The above assumes that:
1) the fields that need to be filled are consecutive
2) the option value is coming from a dataset (that you can place into an array.

ecojohnson
06-27-2001, 01:30 AM
Hi Jesuisiosono.

Thanks for your response. I am struggling with this piece of text as I'm not sure what I am doing wrong. I keep getting the error message "aSubList is not defined". I was wondering if it has something to do with not properly defining the text boxes. If you have any ideas, please let me know.

Here's the code (some of it is written in ColdFusion - I hope it's legible).

<script language="JavaScript">
<!-- Begin
function fillThem() {
for (i=0; i<3; i++) {
document.Dsp_Sel_Project.elements[i].value = aSubList[i];
}
}
// End -->
</script>

<CFQUERY NAME="qSubPick">
SELECT Name, TMajor
FROM TS.TP_SUBD
</CFQUERY>

<FORM ACTION="" METHOD="post" NAME="Dsp_Sel_Project">
<SELECT NAME="ProjectNameList" ID="ProjectNameList" SIZE="5" style="width:470" onChange="fillThem()">
<CFOUTPUT QUERY="qSubPick">
<OPTION VALUE="#qSubPick.name#">#qSubPick.name#</OPTION>
</CFOUTPUT>
</SELECT>
<BR>
<BR>
<CFSET aSubList = ArrayNew(2)>
<CFSET arrayrowcount = "1">
<CFOUTPUT QUERY="qSubPick">
<CFIF qSubPick.CurrentRow EQ 1>
<CFSET aSubList[#arrayrowcount#][1] = #qSubPick.Name#>
<CFSET aSubList[#arrayrowcount#][2] = #qSubPick.TMajor#>
<CFSET PrevLine = #qSubPick.SID#>
</CFIF>
<CFIF PrevLine NEQ #qSubPick.SID#>
<CFSET aSubList[#arrayrowcount#][1] = #qSubPick.Name#>
<CFSET aSubList[#arrayrowcount#][2] = #qSubPick.TMajor#>
<CFSET PrevLine = #qSubPick.SID#>
</CFIF>

#aSubList[arrayrowcount][1]#&nbsp;#aSubList[arrayrowcount][2]#<BR>
</CFOUTPUT>
<BR>
<INPUT TYPE="text">
<INPUT TYPE="text">

</FORM>

Jesuisiosono
06-27-2001, 02:24 AM
Hi eco,

haven't played with coldFusion in a while and my books are no where near me, but.....

aSubList is not defined because (if I'm reading it right) you are creating the list after you call the fillThem function.

Ok, help me out.
1) Where are your text fields?
2) Why are you using coldFusion after you pull the data from the table?
3) How does coldFusion write out the individual option?

<option value='Joe Blow'>Joe Blow</option>

At any rate.....

<select......onChange=fillThem(this)'>


function fillThem(selObj)
{
for (i=0; i < selObj.length; i++)
if (selObj[i].selected)
{
<CFSET aSubList[#arrayrowcount#][1] = #qSubPick.Name#>
<CFSET aSubList[#arrayrowcount#][2] = #qSubPick.TMajor#>
...etc...

}
}

But...you have to declare aSubList before you call the function.

Hope you're not as confused as I am.

ecojohnson
06-27-2001, 06:20 PM
Hi Jesuisiosono,

Thanks for your response. I think I am now more confused than you :-)

The answer to your questions:

1) The text fields were at the bottom <INPUT TYPE="Text">. I didn't give these text fields names as I thought it would populate these text boxes in the order of the array.

2) This was a mistake as I copied and pasted incorrectly into this post.

3) ColdFusion should write out the individual option just like HTML (maybe I don't understand your question).

Anyways, I appreciate your time and help and will understand if you don't have the time to take this any further as I am a very inexperienced user of Javascript.

However, if you want to keep going, I was confused with your last reply. You suggested that I set my array (using CFSET) inside of Javascript. I don't think you can do that using ColdFusion. Do I not understand correctly? Here, I am pasting my code. Maybe that will help clear things us. Thanks again for your help.

<script language="JavaScript">
<!-- Begin
function fillThem(SelObj) {
for (i=0; i<SelObj.length; i++) {
document.Dsp_Sel_Project.elements[i].value = aSubList[i];
}
}
// End -->
</script>

<CFQUERY NAME="qSubPick">
SELECT SID, Name, TMajor
FROM TS.TP_SUBD
</CFQUERY>

<CFSET aSubList = ArrayNew(2)>
<CFSET arrayrowcount = "1">
<CFOUTPUT QUERY="qSubPick">
<CFIF qSubPick.CurrentRow EQ 1>
<CFSET aSubList[#arrayrowcount#][1] = #qSubPick.Name#>
<CFSET aSubList[#arrayrowcount#][2] = #qSubPick.TMajor#>
<CFSET PrevLine = #qSubPick.SID#>
</CFIF>
<CFIF PrevLine NEQ #qSubPick.SID#>
<CFSET aSubList[#arrayrowcount#][1] = #qSubPick.Name#>
<CFSET aSubList[#arrayrowcount#][2] = #qSubPick.TMajor#>
<CFSET PrevLine = #qSubPick.SID#>
</CFIF>
</CFOUTPUT>

<FORM ACTION="" METHOD="post" NAME="Dsp_Sel_Project">
<SELECT NAME="ProjectNameList" ID="ProjectNameList" SIZE="5" style="width:470" onChange="fillThem(this)">
<CFOUTPUT QUERY="qSubPick">
<OPTION VALUE="#qSubPick.name#">#qSubPick.name#</OPTION>
</CFOUTPUT>
</SELECT>
<BR>
<BR>
<INPUT TYPE="text" NAME="Name" VALUE="">
<INPUT TYPE="text" NAME="TMajor" VALUE="">
</FORM>