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

set value of a textbox based on form 1

Status
Not open for further replies.

briancostea

Programmer
Apr 21, 2005
82
US
here is my problem ... i would like to populate the value of a textbox based on a form in a popup window. i keep getting an "object expected" error. i think the problem is that the popup window is a .net page that is submitted. by that i mean there is a search function on the popup ... i tested setting the textbox without doing a search and that worked fine ... it's only when i preform a search and then try to set the value that i get the error.
thanks - brian
 
okay - here is the code in the main page (the one i want to set the value):
function pop()
{
var newWin;
newWin = window.open("code.aspx","airportcodes",'resizable=no,scrollbars=no,width=200,height=250,toolbar=no')
}

<form id="form1" runat="server">
<div>
<table>
<tr><td><asp:Label ID="lblErr" runat="server" Text=""></asp:Label></td></tr>

<tr>
<td>From City or <a href="javascript:pop();"> Airport Code</a></td>
<td><asp:Label ID="lblDepDate" runat="server" Text="Departure Date"></asp:Label></td>
</tr>
</table>
</form>


here is the code the in the popup:
<script>
function setCode()
{
window.opener.document.all.form1.txtDepCity.value="jjj";
window.close();
}
</script>

<script runat="server">
sub search(Source As Object, e As EventArgs)
lblCodes.Text = "<br><a href=javascript:setcode();>" & txtCode.text & "</a>"
end sub
</script>

<html xmlns=" >
<head runat="server">
<title>airport code search</title>
</head>
<body>
<form id="form2" runat="server">
<div>
<asp:TextBox ID="txtCode" runat="server"></asp:TextBox><asp:LinkButton ID="LinkButton1"
runat="server" OnClick="search">search</asp:LinkButton><br />
<asp:Label ID="lblCodes" runat="server" Text=""></asp:Label>&nbsp;<br />
</div>
</form>
</body>
</html>
 
1) you don't have any fields in your main page with the name "txtDepCity". in fact, your fields don't have names at all. give the field the correct name, or use the getElementById method.

2) do not use the "all" collection - it is specific to IE only.

3) call your function in this manner:
Code:
<a href="#" onclick="setcode(); return false;">

*cLFlaVA
----------------------------
[tt]I already made like infinity of those at scout camp...[/tt]
beware of active imagination: [URL unfurl="true"]http://www.coryarthus.com/[/url]

BillyRayPreachersSonIsTheLeetestHax0rDude
[banghead]
 
sorry - was only trying to post relative code, here is my form from the main page:

<form id="form1" runat="server">
<div>
<table>
<tr><td><asp:Label ID="lblErr" runat="server" Text=""></asp:Label></td></tr>

<tr>
<td>From City or <a href="javascript:pop();"> Airport Code</a></td>
<td><asp:Label ID="lblDepDate" runat="server" Text="Departure Date"></asp:Label></td>
</tr>

<tr>
<td><asp:TextBox ID="txtDepCity" runat="server"></asp:TextBox></td>
<td><asp:TextBox ID="txtDepDate" runat="server"></asp:TextBox></td>
<td><a href="javascript:show_calendar('document.all.form1.txtDepDate', document.all.form1.txtDepDate.value);"><img src="cal.gif" width="16" height="16" border="0" alt="Click Here to Pick up the timestamp"></a></td>
</tr>
</table>
</form>
 
use the getElementById method:

Code:
<script [blue]type="text/javascript"[/blue]>
function setCode()
{[blue]
  var d = window.opener.document;
  d.getElementById('txtDepCity').value = 'jjj';[/blue]
  window.close();
}
</script>

*cLFlaVA
----------------------------
[tt]I already made like infinity of those at scout camp...[/tt]
beware of active imagination: [URL unfurl="true"]http://www.coryarthus.com/[/url]

BillyRayPreachersSonIsTheLeetestHax0rDude
[banghead]
 
there are multiple lines of javascript. please provide an error message and error line, or a link to your site.

*cLFlaVA
----------------------------
[tt]I already made like infinity of those at scout camp...[/tt]
beware of active imagination: [URL unfurl="true"]http://www.coryarthus.com/[/url]

BillyRayPreachersSonIsTheLeetestHax0rDude
[banghead]
 
per my first post, the error message is "object expected" line 0. according to the ms script debugger.
 
it would be much more helpful if you posted the code that the browser generates, rather than your ASP code. it is hard to tell where line 0 is - that most likely means inline javascript rather than a function. it could also very well be somewhere that you haven't even posted.

*cLFlaVA
----------------------------
[tt]I already made like infinity of those at scout camp...[/tt]
beware of active imagination: [URL unfurl="true"]http://www.coryarthus.com/[/url]

BillyRayPreachersSonIsTheLeetestHax0rDude
[banghead]
 
and if your error is happening on your call to the search sub, then you're in the wrong forum - that's VBScript.

*cLFlaVA
----------------------------
[tt]I already made like infinity of those at scout camp...[/tt]
beware of active imagination: [URL unfurl="true"]http://www.coryarthus.com/[/url]

BillyRayPreachersSonIsTheLeetestHax0rDude
[banghead]
 
it's not happening there ... the label is being changed fine and dandy. like i said, if i change the code to call the setCode() function instead on search(), it works fine. it has something to do with calling the search subroutine first: here is the generated code:

<script>
function setCode()
{
var d = window.opener.document;
d.getElementById('txtDepCity').value = 'jjj';
window.close();
}
</script>



<html xmlns=" >
<head><title>
airport code search
</title></head>
<body>
<form method="post" action="code.aspx" id="form2">
<div>
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTE2NzIyMzE2NA9kFgICBA9kFgICBA8PFgIeBFRleHQFKTxicj48YSBocmVmPWphdmFzY3JpcHQ6c2V0Y29kZSgpOz5mZXc8L2E+ZGRk4DB3+4WYYrwAA+5O+62Owm+KERI=" />
</div>

<script type="text/javascript">
<!--
var theForm = document.forms['form2'];
if (!theForm) {
theForm = document.form2;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
// -->
</script>


<div>
<input name="txtCode" type="text" value="few" id="txtCode" /><a id="LinkButton1" href="javascript:__doPostBack('LinkButton1','')">search</a><br />
<span id="lblCodes"><br><a href=javascript:setcode();>few</a></span>&nbsp;<br />
</div>
</form>
</body>
</html>
 
in the code you have there, you are calling setcode(), yet the function is described as setCode(). case sensitivity matters. try that and let me know...

*cLFlaVA
----------------------------
[tt]I already made like infinity of those at scout camp...[/tt]
beware of active imagination: [URL unfurl="true"]http://www.coryarthus.com/[/url]

BillyRayPreachersSonIsTheLeetestHax0rDude
[banghead]
 
thanks much - some times it's good to have a fresh set of eyes. i will be sure to leave postive remarks. thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top