Solved

Using Javascript to pass back information into a drop downlist

Posted on 2004-10-07
36
440 Views
Last Modified: 2008-02-01
I have managed to do the following:

<SCRIPT>
var sColor="";              

function callDialog() {
 showModelessDialog("testcallee.asp",window,"status:false;dialogWidth:300px;dialogHeight:150px");
}

function update() {
  document.form1.oColor.value= sColor;
  document.form1.aColor.value= sColor;


}
</SCRIPT>

Text Box
<input type="text" name="oColor" value="">
Search Button
 <INPUT TYPE="button" VALUE="Search" onclick="callDialog()">


testcallee.asp
HTML>
<HEAD>
<TITLE>callee.html</TITLE>
<SCRIPT>

function getInfoAndUpdate() {
  var callerWindowObj = dialogArguments;
  callerWindowObj.sColor = oEnterColor.value;
  callerWindowObj.update();
}

function cancel() {
  var callerWindowObj = dialogArguments;
  callerWindowObj.sColor = "Yellow";
  callerWindowObj.update();
}
</SCRIPT>
</HEAD>
<BODY>
Enter your favorite color:<INPUT ID=oEnterColor><BR><BR>
<INPUT VALUE="Apply" TYPE=button onclick="getInfoAndUpdate();">
<INPUT VALUE="Ok" TYPE=button onclick="getInfoAndUpdate();window.close();">
<INPUT VALUE="Cancel" TYPE=button onclick="cancel();window.close();">
</BODY>
</HTML>

Now i would like to be able to return the value into a drop down list......
which i build from a database

<%Call CreateOption("AssetTag","select distinct ASSETTAG from ASSETTICKET WHERE ASSETTAG IS NOT NULL","ASSETTAG","ASSETTAG", request("AssetTag"))%>

<%sub CreateOption(strName,strTableOrSQL,strValue,strDisplay, strSelected)

'This subroutine expects the following parameters:
' strName is the name of option to  be created
' strTableNameOrSQL the name of table
' strValue is the field from the recordset that holds the value to be stored;
'strDisplay is the field from the recordset that will be displayed in the drop down;
'if a default value is to be selected, that is passed as strSelected. strJavaScript holds
'any event and script to be fired with that event.

dim objRSOption, strIsSelected
set objRSOption=Server.CreateObject("ADODB.RecordSet")
objRSOption.Open strTableOrSQL,dbConn

response.write("<Select Name = '" & strName & "'" & strJavaScript & ">")
response.write(vbCrLF & vbTab &  vbTab & vbTab & vbTab & vbTab & "<Option Value = ''></Option>")

Do until objRSOption.eof
     if Trim(UCase(objRSOption(strValue))) = Trim(UCase(strSelected)) then
          strIsSelected = " selected"
     else
          strIsSelected = ""
     end if
     Response.write(vbCrLF & vbTab &  vbTab & vbTab & vbTab & vbTab & "<Option" & strIsSelected & " Value ='" & objRSOption(strValue) & "'>" & objRSOption(strDisplay) & "</Option>")
     objRSOption.MoveNext
Loop
Response.write(vbCrLF & vbTab &  vbTab & vbTab & vbTab & "</Select>")

objRSOption.close
set objRSOption = Nothing

end sub%>

Possible.............to set the selected dropdown to the oColor coming in from the javascript
0
Comment
Question by:TRACEYMARY
  • 13
  • 12
  • 11
36 Comments
 
LVL 46

Expert Comment

by:fritz_the_blank
Comment Utility
I am not sure that you can do what you are asking here. Since you call the pop up from your page, that means that the page is already rendered, so you can't pass a value to the server-side code that has already exectuted.

FtB
0
 
LVL 46

Expert Comment

by:fritz_the_blank
Comment Utility
1) the asp subroutine function creates the select list
2) the popup appears
3) a value is returned


As you can see, 3 takes place well after 1 does.

0
 
LVL 46

Expert Comment

by:fritz_the_blank
Comment Utility
Having said that, if you return a value from the pop up, it may be possible to reset the value of the select list using client side code.

FtB
0
 
LVL 11

Expert Comment

by:raj3060
Comment Utility
Did you try to add the information to the array??
0
 
LVL 7

Author Comment

by:TRACEYMARY
Comment Utility
Arrays are a little more complex for me...............this javascript is bad enough...

I hear you fritz..
is there a way with the client.......when it comes to do it....
0
 
LVL 46

Expert Comment

by:fritz_the_blank
Comment Utility
Okay, so how do you get the value back from your popup? To what variable is it stored? Also, do you get the text or the value back, i.e., how does this relate to the select list that you want to manipulate?

FtB
0
 
LVL 11

Expert Comment

by:raj3060
Comment Utility
TRACEMARY,
You won't be able to do it with JAVASCRIPT. Here is the deal, I have done it through JSP. I can give you idea how to do it, and may be you can try doing it with ASP.

to get information on JSP follow the link..
http://www.experts-exchange.com/Web/Q_21119382.html

Remember same loginc will be used to update list dynamically..
-Raj
0
 
LVL 46

Expert Comment

by:fritz_the_blank
Comment Utility
>>You won't be able to do it with JAVASCRIPT.<<

Are you sure? If you can pass a value back to the page, then we could do something like:

document.forms[0].elements['AssetTag'].selectedIndex = intIndexToSelect;

Or if we have to, we can iterate through the select list with client-side code until we find the match and then set the selected index then.

FtB
0
 
LVL 11

Expert Comment

by:raj3060
Comment Utility
We did that in TRACEYMARY's last question
http://www.experts-exchange.com/Web/Web_Languages/ASP/Q_21157994.html
Problem is How do we update list dynamically? We can save value from other page in array that's not a problem. But display array values ???
Let me know if need help in adding the values to array, and may be "FtB" cam figure out something to display array to the option list..
-Raj
0
 
LVL 7

Author Comment

by:TRACEYMARY
Comment Utility
Ok....this is getting hard but now im geared to getting it to work.

First Page   a1.asp

<form name="form1" method="GET" action="assetticket_view.asp">
  <table width="100%"  border="0">
    <tr>
      <td width="29%"><span class="style3">Asset Tag </span></td>
      <td width="71%">
        <p>
<input name=t>
<input type=button value=choose onclick=window.open("assetsearch.asp")>
       

assetsearch.asp

I added
<a href='javascript:window.opener.document.form1.t.value=3;self.close()'>return 3></a>

and it returns 3 to the page ......in my correct textbox....called t...great..

Now if i do it to return a recordset value

td>
<%response.write rs("ASSETTAG")  %>
<a href='javascript:window.opener.document.form1.t.value=<%=rs("ASSETTAG")%>;self.close()'>return 3></a>
</td>

I do not get my recordset value...(I see in the browser window it selecting value but on return i get
16384 instead of my recordset value 040000

and 16413 instead of value 040035

That is odd..............(any reason for this)...

Once working i can get on to the Select....part

Cheers




       
0
 
LVL 46

Expert Comment

by:fritz_the_blank
Comment Utility
So, is the idea here not to select an item, but rather, to add an item to the list? If so, we can append a pair to the select list using client-side scripting.

FtB
0
 
LVL 7

Author Comment

by:TRACEYMARY
Comment Utility
Well the idea is
... the user can select from the drop down list
....or if want to get more information as do not know the number then go and use search
   then when that values returns
   put it in the position where the drop down list is..as a selected value.

just as if they had used the drop down feature....
(so that my program only looks at one place for the value and that be in the select list.)

0
 
LVL 46

Expert Comment

by:fritz_the_blank
Comment Utility
Okay, that should be fine then. Once you get the value from the window, we can use it to set the selected property of the select list. Will you be passing the value or the text for the select list from the popup to the page?

FtB
0
 
LVL 11

Expert Comment

by:raj3060
Comment Utility
I might have a good news soon...
I got item inserted to the list now only problem is to get it selected...
0
 
LVL 46

Accepted Solution

by:
fritz_the_blank earned 50 total points
Comment Utility
It is very easy, you just do:

               objSel = document.forms[0].elements['AssetTag']
               intLength = objSel.length;
               objSel.options[intLength]=new Option;
               objSel.options[intLength].value = objSel1.options[i].value;
               objSel.options[intLength].text = objSel1.options[i].text ;
               objSel.selectedIndex = intLength

FtB
0
 
LVL 46

Expert Comment

by:fritz_the_blank
Comment Utility
Oops, that should be:

             objSel = document.forms[0].elements['AssetTag']
               intLength = objSel.length;
               objSel.options[intLength]=new Option;
               objSel.options[intLength].value = strValue;
               objSel.options[intLength].text = strText;
               objSel.selectedIndex = intLength

0
 
LVL 11

Expert Comment

by:raj3060
Comment Utility
Perfect
here is the working code

caller.html
+++++++++++++++++++++++++++
<HEAD>
<TITLE>DialogArguments Example</TITLE>
<SCRIPT>
var sColor="";              

function callDialog() {
 showModelessDialog("callee.html",window,"status:false;dialogWidth:300px;dialogHeight:150px");
}

function update() {
  fbox=sColor;
  tbox = document.form1.list1;
<!-- Begin
sortitems = 1;  // Automatically sort items within lists? (1 or 0)

var no = new Option();
no.value = fbox;
no.text = fbox;
tbox.options[tbox.options.length] = no;
tbox.selectedIndex = no;
fbox= "";
if (sortitems) SortD(tbox);
}

function SortD(box)  {
var temp_opts = new Array();
var temp = new Object();
for(var i=0; i<box.options.length; i++)  {
temp_opts[i] = box.options[i];
}
for(var x=0; x<temp_opts.length-1; x++)  {
for(var y=(x+1); y<temp_opts.length; y++)  {
if(temp_opts[x].text > temp_opts[y].text)  {
temp = temp_opts[x].text;
temp_opts[x].text = temp_opts[y].text;
temp_opts[y].text = temp;
      }
   }
}
for(var i=0; i<box.options.length; i++)  {
box.options[i].value = temp_opts[i].value;
box.options[i].text = temp_opts[i].text;
   }
}
// End -->
</script>
</HEAD>
<BODY>
<form name="form1">
<input name="txtAssetTag" type="text" id="txtAssetTag">      
 
<select multiple size="5" name="list1">
<option value="11"> item 1.1 </option>
<option value="12"> item 1.2 </option>
<option value="13"> item 1.3 </option>
</select>
<INPUT TYPE="button" VALUE="Add Item" onclick="callDialog()">
</form>
</BODY>
</HTML>
++++++++++++++++++++++++++++++

callee.html
===========================
<HTML>
<HEAD>
<TITLE>callee.html</TITLE>
<SCRIPT>
function getInfoAndUpdate() {
  var callerWindowObj = dialogArguments;
  callerWindowObj.sColor = oEnterColor.value;
  callerWindowObj.update();
}
function cancel() {
  var callerWindowObj = dialogArguments;
  callerWindowObj.sColor = "No Item";
  callerWindowObj.update();
}
</SCRIPT>
</HEAD>
<BODY>
Enter your item:<INPUT ID=oEnterColor><BR><BR>

<INPUT VALUE="Ok" TYPE=button onclick="getInfoAndUpdate();window.close();">
<INPUT VALUE="Cancel" TYPE=button onclick="cancel();window.close();">
</BODY>
</HTML>
========================
-Raj
0
 
LVL 7

Author Comment

by:TRACEYMARY
Comment Utility
Ok i made a simple program.

a1.htm

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!-- #INCLUDE FILE="adovbs.Inc" -->
<html>
<head>

<title>Tickets</title>
<link href="CSS/Accessible_Design_Assets.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.style3 {color: #336699; font-weight: bold; }
-->
</style>
</head>

<body>



<form name="form1" method="GET" action="a1.htm">
  <table width="100%"  border="0">
    <tr>
      <td width="29%"><span class="style3">Employee </span></td>
      <td width="71%">
        <p>
<input name=t>
<input type=button value=choose onclick=window.open("assetsearch.asp")>
       
       
           
   
             
        </p></td>
</form>
   
</body>
</html>

calls
assetsearch.asp

using northwind database here of employees
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!-- #INCLUDE FILE="adovbs.Inc" -->
<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Tickets</title>
<link href="CSS/Accessible_Design_Assets.css" rel="stylesheet" type="text/css">



      <%            
dim  dbConn
      set dbConn = server.createobject("adodb.Connection")
      dbConn.open Session("DATABASENORTHWIND")
    Set rs = Server.CreateObject("ADODB.Recordset")
 
 
 %>

<style type="text/css">
<!--
.style3 {color: #336699; font-weight: bold; }
-->
</style>
</head>

<body>

<p align="center">&nbsp;</p>
<p align="center"><strong>
<%
strSQL = "select * from Employees"
   
rs.CursorLocation = 3
rs.Open strSQL, dbConn, 3



rs.PageSize = 15   'Records per page
If Request.Querystring("page") = "" Then
  myPage = 1
Else
  myPage = Request.Querystring("page")
End If

iPages = rs.PageCount
if iPages > 0 then
      rs.AbsolutePage = myPage
else
      response.write "No Employees"
      response.end
end if

Count = 0
%>
<table border="1">
<tr bgcolor="#336699"><td><span class="BulletBackgroundColor">Employee</span></td>
</tr>
<tr>
<%Do While Count < rs.PageSize And Not rs.EOF%>
<tr><td><%response.write rs("FirstName")  %>
<%myvalue = rs("FirstName")%>
<a href='javascript:window.opener.document.form1.t.value=3;self.close()'>return 3></a>
</td>
  <%Count = Count + 1
  rs.MoveNext
Loop
%>
</table>
<%
If CInt(myPage) > 1 Then
%>
  <a href="assetsearch.asp.asp?page=<%= myPage -1 %>">Prev</a>
<%
End If
If rs.PageCount > 1 Then
  For i = 1 To rs.PageCount
%>
  <a href="assetsearch.asp?page=<%= i %>"><%= i %></a>
<%
  Next
End If

If CInt(myPage) < CInt(iPages) Then
%>
  <a href="assetsearch.asp?page=<%= myPage +1 %>">Next</a>
<%
End If
%>

      



      
      
</body>
</html>



This returns the 3 but when i do
<a href='javascript:window.opener.document.form1.t.value=3;self.close()'>return 3></a>

<a href='javascript:window.opener.document.form1.t.value=<%=rs("FirstName")%>;self.close()'>return 3></a>

I get javascript error.

Need to get this bit working then go to the complex select part.

Phew................
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 11

Expert Comment

by:raj3060
Comment Utility
TRACEYMARY, Is that what you are looking for....
0
 
LVL 7

Author Comment

by:TRACEYMARY
Comment Utility
ok just got it working with the recordset listing the values.

<HEAD>
<TITLE>DialogArguments Example</TITLE>
<SCRIPT>
var sColor="";              

function callDialog() {
 showModelessDialog("callee_a.asp",window,"status:false;dialogWidth:300px;dialogHeight:150px");
}

function update() {
  fbox=sColor;
  tbox = document.form1.list1;
<!-- Begin
sortitems = 1;  // Automatically sort items within lists? (1 or 0)

var no = new Option();
no.value = fbox;
no.text = fbox;
tbox.options[tbox.options.length] = no;
tbox.selectedIndex = no;
fbox= "";
if (sortitems) SortD(tbox);
}

function SortD(box)  {
var temp_opts = new Array();
var temp = new Object();
for(var i=0; i<box.options.length; i++)  {
temp_opts[i] = box.options[i];
}
for(var x=0; x<temp_opts.length-1; x++)  {
for(var y=(x+1); y<temp_opts.length; y++)  {
if(temp_opts[x].text > temp_opts[y].text)  {
temp = temp_opts[x].text;
temp_opts[x].text = temp_opts[y].text;
temp_opts[y].text = temp;
      }
   }
}
for(var i=0; i<box.options.length; i++)  {
box.options[i].value = temp_opts[i].value;
box.options[i].text = temp_opts[i].text;
   }
}
// End -->
</script>

<%            
dim  dbConn
      set dbConn = server.createobject("adodb.Connection")
      dbConn.open Session("DATABASENORTHWIND")
    Set rs = Server.CreateObject("ADODB.Recordset")
 
 
 %>
</HEAD>
<BODY>
<form name="form1">
<input name="txtAssetTag" type="text" id="txtAssetTag">      
 <%Call CreateOption("list1","select distinct FIRSTNAME from EMPLOYEES ","FIRSTNAME","FIRSTNAME", request("FIRSTNAME"))%>
<INPUT TYPE="button" VALUE="Add Item" onclick="callDialog()">
</form>

<%sub CreateOption(strName,strTableOrSQL,strValue,strDisplay, strSelected)

'This subroutine expects the following parameters:
' strName is the name of option to  be created
' strTableNameOrSQL the name of table
' strValue is the field from the recordset that holds the value to be stored;
'strDisplay is the field from the recordset that will be displayed in the drop down;
'if a default value is to be selected, that is passed as strSelected. strJavaScript holds
'any event and script to be fired with that event.

dim objRSOption, strIsSelected
set objRSOption=Server.CreateObject("ADODB.RecordSet")
objRSOption.Open strTableOrSQL,dbConn

response.write("<Select Name = '" & strName & "'" & strJavaScript & ">")
response.write(vbCrLF & vbTab &  vbTab & vbTab & vbTab & vbTab & "<Option Value = ''></Option>")

Do until objRSOption.eof
     if Trim(UCase(objRSOption(strValue))) = Trim(UCase(strSelected)) then
          strIsSelected = " selected"
     else
          strIsSelected = ""
     end if
     Response.write(vbCrLF & vbTab &  vbTab & vbTab & vbTab & vbTab & "<Option" & strIsSelected & " Value ='" & objRSOption(strValue) & "'>" & objRSOption(strDisplay) & "</Option>")
     objRSOption.MoveNext
Loop
Response.write(vbCrLF & vbTab &  vbTab & vbTab & vbTab & "</Select>")

objRSOption.close
set objRSOption = Nothing

end sub%>
</BODY>
</HTML>


Now...it returns to the drop down great......................(is there a way to make that the first visible..)...
that be great...

Then the calling program.....................(i need to pass from another paging list of records)..

but so far that pretty dam good programming...



0
 
LVL 7

Author Comment

by:TRACEYMARY
Comment Utility
Ok got both programs here:


<HEAD>
<TITLE>DialogArguments Example</TITLE>
<SCRIPT>
var sColor="";              

function callDialog() {
 showModelessDialog("callee_a.asp",window,"status:false;dialogWidth:300px;dialogHeight:150px");
}

function update() {
  fbox=sColor;
  tbox = document.form1.list1;
<!-- Begin
sortitems = 1;  // Automatically sort items within lists? (1 or 0)

var no = new Option();
no.value = fbox;
no.text = fbox;
tbox.options[tbox.options.length] = no;
tbox.selectedIndex = no;
fbox= "";
if (sortitems) SortD(tbox);
}

function SortD(box)  {
var temp_opts = new Array();
var temp = new Object();
for(var i=0; i<box.options.length; i++)  {
temp_opts[i] = box.options[i];
}
for(var x=0; x<temp_opts.length-1; x++)  {
for(var y=(x+1); y<temp_opts.length; y++)  {
if(temp_opts[x].text > temp_opts[y].text)  {
temp = temp_opts[x].text;
temp_opts[x].text = temp_opts[y].text;
temp_opts[y].text = temp;
      }
   }
}
for(var i=0; i<box.options.length; i++)  {
box.options[i].value = temp_opts[i].value;
box.options[i].text = temp_opts[i].text;
   }
}
// End -->
</script>

<%            
dim  dbConn
      set dbConn = server.createobject("adodb.Connection")
      dbConn.open Session("DATABASENORTHWIND")
    Set rs = Server.CreateObject("ADODB.Recordset")
 
 
 %>
</HEAD>
<BODY>
<form name="form1">
<input name="txtAssetTag" type="text" id="txtAssetTag">      
 <%Call CreateOption("list1","select distinct FIRSTNAME from EMPLOYEES ","FIRSTNAME","FIRSTNAME", request("FIRSTNAME"))%>
<INPUT TYPE="button" VALUE="Add Item" onclick="callDialog()">
</form>

<%sub CreateOption(strName,strTableOrSQL,strValue,strDisplay, strSelected)

'This subroutine expects the following parameters:
' strName is the name of option to  be created
' strTableNameOrSQL the name of table
' strValue is the field from the recordset that holds the value to be stored;
'strDisplay is the field from the recordset that will be displayed in the drop down;
'if a default value is to be selected, that is passed as strSelected. strJavaScript holds
'any event and script to be fired with that event.

dim objRSOption, strIsSelected
set objRSOption=Server.CreateObject("ADODB.RecordSet")
objRSOption.Open strTableOrSQL,dbConn

response.write("<Select Name = '" & strName & "'" & strJavaScript & ">")
response.write(vbCrLF & vbTab &  vbTab & vbTab & vbTab & vbTab & "<Option Value = ''></Option>")

Do until objRSOption.eof
     if Trim(UCase(objRSOption(strValue))) = Trim(UCase(strSelected)) then
          strIsSelected = " selected"
     else
          strIsSelected = ""
     end if
     Response.write(vbCrLF & vbTab &  vbTab & vbTab & vbTab & vbTab & "<Option" & strIsSelected & " Value ='" & objRSOption(strValue) & "'>" & objRSOption(strDisplay) & "</Option>")
     objRSOption.MoveNext
Loop
Response.write(vbCrLF & vbTab &  vbTab & vbTab & vbTab & "</Select>")

objRSOption.close
set objRSOption = Nothing

end sub%>
</BODY>
</HTML>





--------
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<HTML>
<HEAD>
<TITLE>callee.html</TITLE>
<SCRIPT>
function getInfoAndUpdate() {
  var callerWindowObj = dialogArguments;
  callerWindowObj.sColor = oEnterColor.value;
  callerWindowObj.update();
}
function cancel() {
  var callerWindowObj = dialogArguments;
  callerWindowObj.sColor = "No Item";
  callerWindowObj.update();
}
</SCRIPT>
</HEAD>
<BODY>
Enter your item:<INPUT ID=oEnterColor><BR><BR>

<INPUT VALUE="Ok" TYPE=button onclick="getInfoAndUpdate();window.close();">
<INPUT VALUE="Cancel" TYPE=button onclick="cancel();window.close();">

      <%            
dim  dbConn
      set dbConn = server.createobject("adodb.Connection")
      dbConn.open Session("DATABASENORTHWIND")
    Set rs = Server.CreateObject("ADODB.Recordset")
 
 
 %>

<style type="text/css">
<!--
.style3 {color: #336699; font-weight: bold; }
-->
</style>
</head>

<body>

<p align="center">&nbsp;</p>
<p align="center"><strong>
<%
strSQL = "select * from Employees"
   
rs.CursorLocation = 3
rs.Open strSQL, dbConn, 3



rs.PageSize = 15   'Records per page
If Request.Querystring("page") = "" Then
  myPage = 1
Else
  myPage = Request.Querystring("page")
End If

iPages = rs.PageCount
if iPages > 0 then
      rs.AbsolutePage = myPage
else
      response.write "No Employees"
      response.end
end if

Count = 0
%>
<table border="1">
<tr bgcolor="#336699"><td><span class="BulletBackgroundColor">Employee</span></td>
</tr>
<tr>
<%Do While Count < rs.PageSize And Not rs.EOF%>
<tr><td><%response.write rs("FirstName")  %>
<%myvalue = rs("FirstName")%>
<a href='javascript:window.opener.document.form1.t.value=<%=rs("FirstName")%>;self.close()'>return 3></a>
</td>
  <%Count = Count + 1
  rs.MoveNext
Loop
%>
</table>
<%
If CInt(myPage) > 1 Then
%>
  <a href="assetsearch.asp.asp?page=<%= myPage -1 %>">Prev</a>
<%
End If
If rs.PageCount > 1 Then
  For i = 1 To rs.PageCount
%>
  <a href="assetsearch.asp?page=<%= i %>"><%= i %></a>
<%
  Next
End If

If CInt(myPage) < CInt(iPages) Then
%>
  <a href="assetsearch.asp?page=<%= myPage +1 %>">Next</a>
<%
End If
%>

      



      
      
</body>

</HTML>


If i do the add ...name in the enter box it works great.........

I like to be able to select from the pull down list of records in the child page and that value to return into the select box.
and be the first one..

Wow looking like there is light at the end of a tunnel.

0
 
LVL 11

Expert Comment

by:raj3060
Comment Utility
Didn't get you, go again... in simple words...
thanks... and thanks to FtB
0
 
LVL 11

Assisted Solution

by:raj3060
raj3060 earned 450 total points
Comment Utility
OK, that's simple.
Instead of having input box on child page, display your result in the list box, and then you should be able to read the selected value same as we are reading the text box value, but remember you will need to send two values to the parent page, first option value, and second option text.
You want to display value at the top then don't sort it, and see where does it go. I am afraid it will go to the bottom.. But we can figure out something to pull it at the top.
Gotta go to the meeting. Will be back about 3:00 CST or not, depends how much user is gonna suck our brain...
See you later.
0
 
LVL 7

Author Comment

by:TRACEYMARY
Comment Utility
Smiles ok...getting carried away with myself over here

2nd Page.
I display a list of records from database
so rather than type in the text box...enter your ..

you select the record in the paging section

So im trying to make the following be the value which is from database list rather than the text box field value

<input ID=oEnterColor value="<%=rs("FirstName")%>">
<INPUT VALUE="Ok" TYPE=button onclick="getInfoAndUpdate();window.close();">

instead of
Enter your item:<INPUT ID=oEnterColor><BR><BR>

<INPUT VALUE="Ok" TYPE=button onclick="getInfoAndUpdate();window.close();">
<INPUT VALUE="Cancel" TYPE=button onclick="cancel();window.close();">


It works but it returns value undefined......

Cheers
0
 
LVL 11

Expert Comment

by:raj3060
Comment Utility
but I guess this way you will be getting only on value, you said you want to select from the list, something like this:

<HTML>
<HEAD>
<TITLE>callee.html</TITLE>
<SCRIPT>
function getInfoAndUpdate() {
  var callerWindowObj = dialogArguments;
  callerWindowObj.sValue = oEnterColor.value;
      callerWindowObj.sText = oEnterColor.text;
  callerWindowObj.update();
}
function cancel() {
  var callerWindowObj = dialogArguments;
  callerWindowObj.sValue = "";
      callerWindowObj.sText = "";
  callerWindowObj.update();
}
</SCRIPT>
</HEAD>
<BODY>
<select name="oEnterColor">
<option value="1">One  // these options will be coming from database....
<option value="2">Two
<option value="3">Three
</select>

<INPUT VALUE="Ok" TYPE=button onclick="getInfoAndUpdate();window.close();">
<INPUT VALUE="Cancel" TYPE=button onclick="cancel();window.close();">
</BODY>
</HTML>

===============
I am getting undefined too... but it will work, keep trying.. I will be back soon...
Bye
0
 
LVL 7

Author Comment

by:TRACEYMARY
Comment Utility
Not a problem thanks
0
 
LVL 46

Expert Comment

by:fritz_the_blank
Comment Utility
Do you have a link that I can look at?

FtB
0
 
LVL 7

Author Comment

by:TRACEYMARY
Comment Utility
Ok i managed to get it to work using the

<a href="javascript:window.opener.document.form1.category.value='<%=rs("CATEGORY_ID")%>';self.close();"><%=rs("CATEGORY_ID")%></a>

and returning to this
 <input name=category>
<input type=button value=choose onclick=window.open("call_search.asp")>

The other javascript part is really good raj......but i think i have to get up to speed on javascript really quickly.

So i use the this example as it works....................and is easy to amend if i get any errors.
As to populate the list drop down ..........(thats a luxury).

So i keep working on the other part.......................but for now got a work around.

Thanks ........i close out the bug....

If i get a work around for this: using modal
<HEAD>
<TITLE>DialogArguments Example</TITLE>
<SCRIPT>
var sColor="";              

function callDialog() {
 showModelessDialog("callee_a.asp",window,"status:false;dialogWidth:300px;dialogHeight:150px");
}

function update() {
  fbox=sColor;
  tbox = document.form1.list1;
<!-- Begin
sortitems = 1;  // Automatically sort items within lists? (1 or 0)

var no = new Option();
no.value = fbox;
no.text = fbox;
tbox.options[tbox.options.length] = no;
tbox.selectedIndex = no;
fbox= "";
if (sortitems) SortD(tbox);
}

function SortD(box)  {
var temp_opts = new Array();
var temp = new Object();
for(var i=0; i<box.options.length; i++)  {
temp_opts[i] = box.options[i];
}
for(var x=0; x<temp_opts.length-1; x++)  {
for(var y=(x+1); y<temp_opts.length; y++)  {
if(temp_opts[x].text > temp_opts[y].text)  {
temp = temp_opts[x].text;
temp_opts[x].text = temp_opts[y].text;
temp_opts[y].text = temp;
      }
   }
}
for(var i=0; i<box.options.length; i++)  {
box.options[i].value = temp_opts[i].value;
box.options[i].text = temp_opts[i].text;
   }
}
// End -->
</script>

<%            
dim  dbConn
      set dbConn = server.createobject("adodb.Connection")
      dbConn.open Session("DATABASENORTHWIND")
    Set rs = Server.CreateObject("ADODB.Recordset")
 
 
 %>
</HEAD>
<BODY>
<form name="form1">
<input name="txtAssetTag" type="text" id="txtAssetTag">      
 <%Call CreateOption("list1","select distinct FIRSTNAME from EMPLOYEES ","FIRSTNAME","FIRSTNAME", request("FIRSTNAME"))%>
<INPUT TYPE="button" VALUE="Add Item" onclick="callDialog()">
</form>

<%sub CreateOption(strName,strTableOrSQL,strValue,strDisplay, strSelected)

'This subroutine expects the following parameters:
' strName is the name of option to  be created
' strTableNameOrSQL the name of table
' strValue is the field from the recordset that holds the value to be stored;
'strDisplay is the field from the recordset that will be displayed in the drop down;
'if a default value is to be selected, that is passed as strSelected. strJavaScript holds
'any event and script to be fired with that event.

dim objRSOption, strIsSelected
set objRSOption=Server.CreateObject("ADODB.RecordSet")
objRSOption.Open strTableOrSQL,dbConn

response.write("<Select Name = '" & strName & "'" & strJavaScript & ">")
response.write(vbCrLF & vbTab &  vbTab & vbTab & vbTab & vbTab & "<Option Value = ''></Option>")

Do until objRSOption.eof
     if Trim(UCase(objRSOption(strValue))) = Trim(UCase(strSelected)) then
          strIsSelected = " selected"
     else
          strIsSelected = ""
     end if
     Response.write(vbCrLF & vbTab &  vbTab & vbTab & vbTab & vbTab & "<Option" & strIsSelected & " Value ='" & objRSOption(strValue) & "'>" & objRSOption(strDisplay) & "</Option>")
     objRSOption.MoveNext
Loop
Response.write(vbCrLF & vbTab &  vbTab & vbTab & vbTab & "</Select>")

objRSOption.close
set objRSOption = Nothing

end sub%>
</BODY>
</HTML>

-----
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<HTML>
<HEAD>
<TITLE>callee.html</TITLE>
<SCRIPT>
function getInfoAndUpdate() {
  var callerWindowObj = dialogArguments;
  callerWindowObj.sColor = oEnterColor.value;
  callerWindowObj.update();
}
function cancel() {
  var callerWindowObj = dialogArguments;
  callerWindowObj.sColor = "No Item";
  callerWindowObj.update();
}
</SCRIPT>
</HEAD>
<BODY>


<INPUT VALUE="Ok" TYPE=button onclick="getInfoAndUpdate();window.close();">
<INPUT VALUE="Cancel" TYPE=button onclick="cancel();window.close();">

      <%            
dim  dbConn
      set dbConn = server.createobject("adodb.Connection")
      dbConn.open Session("DATABASENORTHWIND")
    Set rs = Server.CreateObject("ADODB.Recordset")
 
 
 %>

<style type="text/css">
<!--
.style3 {color: #336699; font-weight: bold; }
-->
</style>

</head>

<body>

<p align="center">&nbsp;</p>
<p align="center"><strong>
<%
strSQL = "select * from Employees"
   
rs.CursorLocation = 3
rs.Open strSQL, dbConn, 3



rs.PageSize = 15   'Records per page
If Request.Querystring("page") = "" Then
  myPage = 1
Else
  myPage = Request.Querystring("page")
End If

iPages = rs.PageCount
if iPages > 0 then
      rs.AbsolutePage = myPage
else
      response.write "No Employees"
      response.end
end if

Count = 0
%>
<table border="1">
<tr bgcolor="#336699"><td><span class="BulletBackgroundColor">Employee</span></td>
</tr>
<tr>
<%Do While Count < rs.PageSize And Not rs.EOF%>
<tr><td><%response.write rs("FirstName")  %>
<%myvalue = rs("FirstName")%>


  <input ID=oEnterColor value="<%=rs("FirstName")%>">
<INPUT VALUE="Ok" TYPE=button onclick="getInfoAndUpdate();window.close();">


<a href='javascript:window.opener.document.form1.t.value=<%=rs("FirstName")%>;self.close()'>return 3></a>
</td>
  <%Count = Count + 1
  rs.MoveNext
Loop
%>
</table>
<%
If CInt(myPage) > 1 Then
%>
  <a href="assetsearch.asp.asp?page=<%= myPage -1 %>">Prev</a>
<%
End If
If rs.PageCount > 1 Then
  For i = 1 To rs.PageCount
%>
  <a href="assetsearch.asp?page=<%= i %>"><%= i %></a>
<%
  Next
End If

If CInt(myPage) < CInt(iPages) Then
%>
  <a href="assetsearch.asp?page=<%= myPage +1 %>">Next</a>
<%
End If
%>

      



      
      
</body>

</HTML>


I post to this .....when i get that working
           
0
 
LVL 11

Expert Comment

by:raj3060
Comment Utility
Are you getting the List (option) values from the database for second page(child). If so work on displaying all values to the drop down list some thing like:

<select name = "oEnterValue">

>query and get resultset
>check for the end of rs i.e. loop
>get the value i.e. myvalue = rs("FirstName")
<option value = <=%myvalue%>><%myvalue%></option>
repeat untill get all values.
</select>

do this and let me know if you are able to display all values in the drop down box..

-Raj
0
 
LVL 11

Expert Comment

by:raj3060
Comment Utility
Once you are able to get that working then use this. I got this one working with drop down list on child page..

<HTML>
<HEAD>
<TITLE>callee.html</TITLE>
<SCRIPT>
function getInfoAndUpdate() {
  var callerWindowObj = dialogArguments;
  callerWindowObj.sColor = oEnterColor.value;    
  callerWindowObj.update();
}
function cancel() {
  var callerWindowObj = dialogArguments;
  callerWindowObj.sColor = "";
      callerWindowObj.update();
}
</SCRIPT>
</HEAD>
<BODY>
<select name="oEnterColor">  
<option value="One">One</option>
<option value="Two">Two</option>
<option value="Three">Three</option>
</select>

<INPUT VALUE="Ok" TYPE=button onclick="getInfoAndUpdate();window.close();">
<INPUT VALUE="Cancel" TYPE=button onclick="cancel();window.close();">
</BODY>
</HTML>
===================

drop down part will be replaced with your working part i.e.

<select name = "oEnterValue">
<%
>query and get resultset
>check for the end of rs i.e. loop
>get the value i.e. myvalue = rs("FirstName") %>
<option value = <=%myvalue%>><%=myvalue%></option>
<%repeat untill get all values.%>

</select>
=========================
This will work...
0
 
LVL 11

Expert Comment

by:raj3060
Comment Utility
Thanks Dr.  Fairfield, if you didn't have question about being this done with JavaScript, we would have not tried..
0
 
LVL 46

Expert Comment

by:fritz_the_blank
Comment Utility
Happy to help but you did most of the heavy lifting.

Doc (a.ka. FtB)

0
 
LVL 7

Author Comment

by:TRACEYMARY
Comment Utility
raj3060 just tried it....works a treat............

Javascript is pretty neat and powerful ......never knew it ......

So for me to learn its just "javascript" thats whats i need to get book or course on

I appreciate you sticking with a newbie in javascript here..
Now weekend i can take code home and go over it.

Cheers
0
 
LVL 7

Author Comment

by:TRACEYMARY
Comment Utility
One last question.

What application you using to write your javascript in...

So that you see the object.x.come up

like when i type in response.    i get promted with list of values whilst typing

cheers
0
 
LVL 46

Expert Comment

by:fritz_the_blank
Comment Utility
You can write in Note pad or any text editor. Nothing special is required. The only problem with JavaScript is that if you rely on it, and the person has it disabled in the browser, then you may find yourself in trouble.

FtB
0
 
LVL 11

Expert Comment

by:raj3060
Comment Utility
FtB is right, you can use any free editors available out there, I use HTMLKit, it's pretty neat, it has a nice feature that checks your code for any error, and or completes your code if you forgot something somewhere in the code. Doc is right about JavaScript too, because it is not compatible on all browsers, and acts real funky sometimes. I try to stay away from it as much as I can, because stuff you can do with JavaScript you can do with ASP or JSP too, and that's more reliable.
Stuff we did is not that easy, because I tried to do something like that before, could not do it. I learnt something new too.
You are welcome, and feel free to ask any question in future.
Have a nice weekend to you and FtB.
-raj
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now