document.getElementById(), error in content page content page

D

Dave L

Could someone explain: I have a java popup window function that I would
like to pass a querystring ID from a hiddenfield on my asp.net content page.
The following code works. Note: for this test I simply set the hiddefield
var TransID.value = 21 in btnPopUp.click event See Item 1. The thing I
don't understand is why can't I have the function take the TransID as a
parameter. see Item 2.


**************Item 1.****************

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">

<script type="text/javascript" >
function PopUp() {

var InqID = document.getElementById('<%=TransID.ClientID%>').value;
alert(InqID);
}

</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
<asp:Button ID="btnPopUp" runat="server" Text="Press Me"
OnClientClick="javascript:popUp();" />

<asp:HiddenField ID="TransID" runat="server" />
</asp:Content>



*************Item 2.****************

This Fails

***********************************


<script type="text/javascript" >
function PopUp(obj) {

var InqID = document.getElementById(obj).value;
alert(InqID);
}

</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
<asp:Button ID="btnPopUp" runat="server" Text="Press Me"
OnClientClick="javascript:popUp('<%=TransID.ClientID%>');" />

<asp:HiddenField ID="TransID" runat="server" />
</asp:Content>


Any help would be greatly appreaciated.

Feel free to email me at (e-mail address removed)
 
M

Mr. Arnold

Dave said:
Could someone explain: I have a java popup window function that I would
like to pass a querystring ID from a hiddenfield on my asp.net content
page. The following code works. Note: for this test I simply set the
hiddefield var TransID.value = 21 in btnPopUp.click event See Item 1.
The thing I don't understand is why can't I have the function take the
TransID as a parameter. see Item 2.

<script type="text/javascript" >
function PopUp(obj) {

var InqID = document.getElementById(obj).value;
alert(InqID);
}

</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
<asp:Button ID="btnPopUp" runat="server" Text="Press Me"
OnClientClick="javascript:popUp('<%=TransID.ClientID%>');" />

<asp:HiddenField ID="TransID" runat="server" />
</asp:Content>
------------------------------------------------

Didn't you pass the control as an object to the function?

Maybe, I am wrong, but the object has the data and you don't need to do
getEbyID in the function, because you passed the control to the function.

var InqID = object.value;

But first do an alert(obj) to even see if you have an object.
 
G

Göran Andersson

Mr. Arnold said:
<script type="text/javascript" >
function PopUp(obj) {

var InqID = document.getElementById(obj).value;
alert(InqID);
}

</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
<asp:Button ID="btnPopUp" runat="server" Text="Press Me"
OnClientClick="javascript:popUp('<%=TransID.ClientID%>');" />

<asp:HiddenField ID="TransID" runat="server" />
</asp:Content>
------------------------------------------------

Didn't you pass the control as an object to the function?

Maybe, I am wrong, but the object has the data and you don't need to do
getEbyID in the function, because you passed the control to the function.

var InqID = object.value;

But first do an alert(obj) to even see if you have an object.

No, it's not an object, it's a string. Note the apostrophes around the
value in the function call.
 
G

Göran Andersson

Dave said:
Could someone explain: I have a java popup window function that I would
like to pass a querystring ID from a hiddenfield on my asp.net content
page. The following code works. Note: for this test I simply set the
hiddefield var TransID.value = 21 in btnPopUp.click event See Item 1.
The thing I don't understand is why can't I have the function take the
TransID as a parameter. see Item 2.


**************Item 1.****************

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">

<script type="text/javascript" >
function PopUp() {

var InqID = document.getElementById('<%=TransID.ClientID%>').value;
alert(InqID);
}

</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
<asp:Button ID="btnPopUp" runat="server" Text="Press Me"
OnClientClick="javascript:popUp();" />

<asp:HiddenField ID="TransID" runat="server" />
</asp:Content>



*************Item 2.****************

This Fails

***********************************


<script type="text/javascript" >
function PopUp(obj) {

var InqID = document.getElementById(obj).value;
alert(InqID);
}

</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
<asp:Button ID="btnPopUp" runat="server" Text="Press Me"
OnClientClick="javascript:popUp('<%=TransID.ClientID%>');" />

<asp:HiddenField ID="TransID" runat="server" />
</asp:Content>


Any help would be greatly appreaciated.

Feel free to email me at (e-mail address removed)

The problem is that you can't have a script tag inside the Button tag.

The easiest is to set the OnClientClick value from code behind:

btnPopUp.OnClientClick = "PopUp('" + TransID.ClientID + "')";

(Note that the javascript: protocol is only used when you put script in
an URL, e.g. in the href attribute of a link. If you use it in the
onclick attribute, it will instead be interpreted as a label.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,830
Latest member
ZADIva7383

Latest Threads

Top