Solved

Using Javascript to pass back information into a drop downlist

Posted on 2004-10-07
36
449 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
ID: 12248159
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
ID: 12248175
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
ID: 12248181
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Expert Comment

by:raj3060
ID: 12248423
Did you try to add the information to the array??
0
 
LVL 7

Author Comment

by:TRACEYMARY
ID: 12249869
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
ID: 12249938
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
ID: 12250128
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
ID: 12250207
>>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
ID: 12250453
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
ID: 12250487
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
ID: 12250491
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
ID: 12250573
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
ID: 12250708
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
ID: 12250810
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
ID: 12250900
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
ID: 12250910
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
ID: 12250975
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
ID: 12251010
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
 
LVL 11

Expert Comment

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

Author Comment

by:TRACEYMARY
ID: 12251169
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
ID: 12251253
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
ID: 12251257
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
ID: 12251367
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
ID: 12251422
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
ID: 12251514
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
ID: 12251636
Not a problem thanks
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 12251649
Do you have a link that I can look at?

FtB
0
 
LVL 7

Author Comment

by:TRACEYMARY
ID: 12251859
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
ID: 12254140
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
ID: 12254250
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
ID: 12254286
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
ID: 12254405
Happy to help but you did most of the heavy lifting.

Doc (a.ka. FtB)

0
 
LVL 7

Author Comment

by:TRACEYMARY
ID: 12257862
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
ID: 12258076
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
ID: 12258093
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
ID: 12258327
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

680 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