Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Again I need help please ASAP.

Status
Not open for further replies.

MrHelpMe

Technical User
May 1, 2001
203
CA
Hello again,

I am stuck at doing some passing of data. I have a form that has 3 cascading dynamically populated list boxes. The problem is that when I click on the first list box, I want the values selected to be passed into another page. I have created a javascript functions to hold these values, however I want to pass these values to a hidden txt box field when the user selects them. And then I want to pass the selected values to another page. How do I do that. Thanks again.

function readtext(form){
for (x=2;x<document.form1.combo1.length;x++){
if (document.form1.combo1[x].selected){
var TestVar = (document.form1.combo1.options[x].text);
alert("You typed: " + TestVar);
}
}
}
 
Do you mean something like this?
Code:
<html>
<head>
<title>Combo boxes</title>
<script type="text/javascript">
<!--

function setHidden(sel)
{
  var targ = sel.form.elements[sel.name+"txt"];
  targ.value = sel.options[sel.selectedIndex].value;
}

// -->
</script>
</head>
<body>
<form name="aform" id="aform">
 <select name="sel1" id="sel1" onchange="setHidden(this);">
  <option value="a">A</option>
  <option value="b">B</option>
  <option value="c">C</option>
 </select>
 <input type="hidden" name="sel1txt" id="sel1txt" value="">
</form>
</body>
</html>
Not sure what you mean about passing to another page; do you want to submit the form? When?

--Chessbot

"Violence is the last refuge of the incompetent." -- Asimov, Foundation
 
Sorry chessbot,

What I need to happen is when the page loads, it populated 1 text box from a database. The problem is that when I submit that value stored in a text box and I response.write that value to the page I get a int value. 0, 1, 2, 3 etc.
So I created the javascript functions that looks at the value in the array and spits out the text of it. All I need is to pass that text value to a stored procedure because my Stored procedure is waiting for the text value rather then the int. I hope that clear.

Again I created this
function readtext(form){
for (x=2;x<document.form1.combo1.length;x++){
if (document.form1.combo1[x].selected){
var TestVar = (document.form1.combo1.options[x].text);
//alert("You typed: " + TestVar);
}
}
}

And I created a hidden field to store this value but I do not know how to store it.
<input type=hidden name="Catlist" ID="Hidden1" value="">

Once it is stored, I will click the submit button, it will goto a page and then I will have code like this that calls it

Session("oRpt").ParameterFields.GetItemByName("@Category").AddCurrentValue(CStr(request.form("CatList")))

I hope this is clear. Sorry I'm new to the languages. Thanks again.
 
Oh, ok. Is this what you want?
Code:
<html>
<head>
<title>...</title>
<script type="text/javascript">
<!--
function readtext(sel)
{
  if (elem.selectedIndex > 1)
    return elem.options[elem.selectedIndex].text;
  else
    return "";
}
// -->
</script>
</head>
<body>
<form name="aform" id="aform" action="?" method="post" onsubmit="this.elements['CatList'].value = readtext(this.elements['combo1']);">
<input type="hidden" name="CatList" value="">
<select name="combo1" id="combo1">
 <option value="0">Choose one</option>
 <option value="1">----------</option>
 <option value="2">Third option</option>
 <option value="3">Fourth option</option>
</select>
</form>
</body>
</html>
This works if you aren't using a multiple select. If you are, use your function but return the value.

--Chessbot

"Violence is the last refuge of the incompetent." -- Asimov, Foundation
 
Hi Chessbot,

I tried all the code and plugged into my code but it doesn;t work. When the form submits to my other page(report.asp) and I response.write(request.form("CatList")) I see a blank vlaue selected. Why is the value(s) selected not getting passed on submit. Thanks again for all your hard work.
 
Are you selecting an option other than the first two? What browser are you using?

--Chessbot

"Violence is the last refuge of the incompetent." -- Asimov, Foundation
 
I am using internet explorer 6.0. As for selecting an option other then the first. The answer is no. Actually, I have my list coming back dynamically from a database so I am not using your options. Also there is no submit button in your example. Does that not matter. There is a submit on my page. Thanks again.
 
Change to
Code:
function readtext(sel)
{
  return elem.options[elem.selectedIndex].text;
}
Are you getting any errors?

--Chessbot

"Violence is the last refuge of the incompetent." -- Asimov, Foundation
 
Hi Chessbot,

I had a chance to try this again and I am still getting a blank value passed when I response write. Any other ideas, maybe on how to troubleshoot this. Thanks again.
 
What are you trying to response.write? The value of sel1txt or the value of sel1?

This problem could be solved by dynamically creating your drop-down boxes in this manner:

Code:
<select name="s">
  <option value="stuff">stuff</option>
  <option value="stuff2">stuff2</option>
  <option value="stuff3">stuff3</option>
</select>

This way, the value of s when you response.write it will be the actual selected value.

*cLFlaVA
----------------------------
[tt]insert funny quotation here.[/tt]
 
Sorry guys maybe I should explain myself. I created the hidden field CATLIST. Do I not need the hiddent field. Combo1 is currently populating the list with integers. So this is why I created a hidden field to store the txt of the values from combo1. So to answer your question I am response writing CATLIST. I will then do the same for TypeList and ItemList. Is this correct?

<FORM NAME=form1 METHOD="post" ACTION="" onsubmit="this.elements['CatList'].value = readtext(this.elements['combo1']);">
<TABLE WIDTH="80%" ALIGN="center" cellspacing="0" >
<input type="hidden" name="CatList" value="">
<input name="Typelist" type=hidden value="" ID="Hidden2">
<input name="Itemlist" type=hidden value="" ID="Hidden3">
<TR>
<TD align="center" colspan="8"> <BR>Select the Category(s), Types(s), Item(s), Department(s) and Status to be included in the report:<BR><BR></TD>
</TR>
<TR>
<TD width="33%" ALIGN="center"><B>Category(s)</B></TD>
<TD width="34%" ALIGN="center"><B>Type(s)</B></TD>
<TD width="33%" ALIGN="center"><B>Item(s)</B></TD>
</TR>
<TR>
<TD ALIGN="center"><SELECT NAME="combo1" SIZE="6" style="width:175px;" ONCHANGE="clickcombo(this)" multiple>
</SELECT></TD>
<TD ALIGN="center"><SELECT NAME="combo2" SIZE="6" style="width:175px;" ONCHANGE="clickcombo(this);" MULTIPLE></SELECT></TD>
<TD ALIGN="center"><SELECT NAME="combo3" SIZE="6" style="width:175px;" MULTIPLE></SELECT>
</TD>
</TR>
</TABLE>
 
Can you do me the following favor?

Change this:

Code:
onsubmit="this.elements['CatList'].value = readtext(this.elements['combo1']);"
to this:
Code:
onsubmit="this.elements['CatList'].value = readtext(this.elements['combo1']); alert(this.elements['CatList'].value);"

Let me know what you see (is it blank)? Then, can you show your clickcombo function?

*cLFlaVA
----------------------------
[tt]insert funny quotation here.[/tt]
 
Yes it is blank and the click combo function is as follows.

function clickcombo(elem){
num=elem.name.substr(elem.name.length-1,1)
NumToLetter=String.fromCharCode(num.charCodeAt(0)+49)
allchosen=false
if (elem[1].selected){
clearsubcombos(num)
for (x=0;x<elem.length;x++)
{elem[x].selected = false;}
elem[1].selected = true;
return;
}else{
if (elem[0].selected){
allchosen=true
for (x=0;x<elem.length;x++){
if (x!=1) {
elem[x].selected = true;
}
}
}
}
 
what is that function supposed to be doing?

*cLFlaVA
----------------------------
[tt]insert funny quotation here.[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top