Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   document.getElementById(), error in content page content page (http://www.velocityreviews.com/forums/t716702-document-getelementbyid-error-in-content-page-content-page.html)

Dave L 03-04-2010 02:31 AM

document.getElementById(), error in content page content page
 
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%>').v alue;
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.Client ID%>');" />

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


Any help would be greatly appreaciated.

Feel free to email me at duckkiller53@gmail.com


Mr. Arnold 03-04-2010 04:44 AM

Re: document.getElementById(), error in content page content page
 
Dave L wrote:
> 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.Client ID%>');" />

<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öran Andersson 03-04-2010 08:46 AM

Re: document.getElementById(), error in content page content page
 
Mr. Arnold wrote:
> Dave L wrote:
>> 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.Client ID%>');" />
>
> <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öran Andersson
_____
http://www.guffa.com

Göran Andersson 03-04-2010 08:50 AM

Re: document.getElementById(), error in content page content page
 
Dave L wrote:
> 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%>').v alue;
> 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.Client ID%>');" />
>
> <asp:HiddenField ID="TransID" runat="server" />
> </asp:Content>
>
>
> Any help would be greatly appreaciated.
>
> Feel free to email me at duckkiller53@gmail.com


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.)

--
Göran Andersson
_____
http://www.guffa.com


All times are GMT. The time now is 12:43 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.