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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript values into ASP

Status
Not open for further replies.

unclerico

IS-IT--Management
Joined
Jun 8, 2005
Messages
2,738
Location
US
The title of this topic is a little vague, but essentially waht I am trying to do is this:

I have a form that has a list box on the left side that is populated with names; two buttons, Add & Remove, in the middle that will add/remove names from the list boxes; a list box on the right that will be populated/unpopulated from the list on the left. I can successfully add/remove items from the left/right list boxes no problem; however, when I submit the page and try to do a response.write request.form("lstDest") the page is empty and of course when I view source on the main page the <option>s in each list box don't change. Here is my code:

addremove.js
Code:
function addOption(theSel, theText, theValue)
{
	var newOpt = new Option(theText, theValue);
	var selLength = theSel.length;
	theSel.options[selLength] = newOpt;
}

function deleteOption(theSel, theIndex)
{	
	var selLength = theSel.length;
	if(selLength>0)
	{
		theSel.options[theIndex] = null;
	}
}

function moveOptions(theSelFrom, theSelTo)
{
	
	var selLength = theSelFrom.length;
	var selectedText = new Array();
	var selectedValues = new Array();
	var selectedCount = 0;
	
	var i;
	
	// Find the selected Options in reverse order
	// and delete them from the 'from' Select.
	for(i=selLength-1; i>=0; i--)
	{
		if(theSelFrom.options[i].selected)
		{
			selectedText[selectedCount] = theSelFrom.options[i].text;
			selectedValues[selectedCount] = theSelFrom.options[i].value;
			deleteOption(theSelFrom, i);
			selectedCount++;
		}
	}
	
	// Add the selected text/values in reverse order.
	// This will add the Options to the 'to' Select
	// in the same order as they were in the 'from' Select.
	for(i=selectedCount-1; i>=0; i--)
	{
		addOption(theSelTo, selectedText[i], selectedValues[i]);
	}
	
}
Report.asp
Code:
.
.
.
<select name="lstSource" id="lstSource" multiple size="30">
					<%
					For i = 1 To rsReports.RecordCount
			
						If rsReports("sn") <> "" AND rsReports("mail") <> "" Then
						%>
						<option value="<%= rsReports("mail") & ", " & rsReports("givenname") & " " & rsReports("sn") %>"><%= rsReports("sn") & ", " & rsReports("givenname") %></option>	
						<%
						End If
				
						rsReports.MoveNext
					
					Next
					%>
				</select>
				<input type="button" name="btnAdd" id="btnAdd" value="Add" onClick="moveOptions(document.frm1.lstSource, document.frm1.lstDest);" style="width:70px" />
				<input type="button" name="btnRem" id="btnRem" value="Remove" onClick="moveOptions(document.frm1.lstDest, document.frm1.lstSource);" style="width:70px" />
				<select name="lstDest" id="lstDest" multiple size="30">
				</select>
				<input type="submit" id="btnSubmit" name="btnSubmit" value="Go" width="70px" />
	<%
	Set rsReports = Nothing
	Set conn = Nothing
	%>	
</form>
viewresults.asp
Code:
.
.
.
<body>
<%
Response.Write Request.Form("lstDest")
%>
</body>
.
.
.
I hope that I have explained myself well enough. Thanks for any help that you can give me.
 
I just ended up creating a hidden field and when I went to submit the form i looped through the lstDest listbox and added all of the values to the hidden field...it works but maybe it isn't the best way??
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top