I want the value of this hidden field to be set by a javascript popup window, using the following code:
function getRecepientEmail() {
var email= prompt('Please enter your email address', ' ');
var ID = this.document.getElementById("recepientEmail");
ID.Value = email;
alert(ID.Value);
}
The server-side sub SendEmail exists and works properly.
When I click the link, I get prompted for the email address, and I am then given an alert box. This box contains the email address I typed in, telling me JS has set the value of the hidden field accordingly. However, when the postback is completed, the
value of the hidden field remains blank. I have used Firefox's WebDeveloper plugin to change the POST to a GET, allowing me to see what values are passed through, and the recepientEmail field is empty.
This seems to be some form of discrepency between JS and .NET that I cannot figure out, any suggestions?
What you are actually doing is creating a new property called "Value" (javascript is case sensitive and so "Value" and "value" are different). Change the V to a v.
Yes, I found a similar post last night after I had submitted this, and you are correct, changing the "Value" to "value" solves my problem. Thanks though!
dageyra
Member
241 Points
53 Posts
Setting ASP:HiddenField value with javascript
Feb 20, 2007 10:07 PM|LINK
Hello All:
I have an ASP hidden field such as:
<asp:HiddenField ID="recepientEmail" runat="server"></asp:HiddenField>
I want the value of this hidden field to be set by a javascript popup window, using the following code:
function getRecepientEmail() {
var email= prompt('Please enter your email address', ' ');
var ID = this.document.getElementById("recepientEmail");
ID.Value = email;
alert(ID.Value);
}
I have a link:
<asp:LinkButton ID="EmailLink" runat="server" CssClass="actionLink" OnClick="SendEmail">Email...</asp:LinkButton>
I set the onclick (JS) attribute of this link on page load with:
EmailLink.Attributes("onClick") = "getRecepientEmail();"
The server-side sub SendEmail exists and works properly.
When I click the link, I get prompted for the email address, and I am then given an alert box. This box contains the email address I typed in, telling me JS has set the value of the hidden field accordingly. However, when the postback is completed, the value of the hidden field remains blank. I have used Firefox's WebDeveloper plugin to change the POST to a GET, allowing me to see what values are passed through, and the recepientEmail field is empty.
This seems to be some form of discrepency between JS and .NET that I cannot figure out, any suggestions?
stevenbey
All-Star
16526 Points
3378 Posts
Re: Setting ASP:HiddenField value with javascript
Feb 21, 2007 03:26 AM|LINK
What you are actually doing is creating a new property called "Value" (javascript is case sensitive and so "Value" and "value" are different). Change the V to a v.
http://stevenbey.com
Recursion: see Recursion
dageyra
Member
241 Points
53 Posts
Re: Setting ASP:HiddenField value with javascript
Feb 21, 2007 02:58 PM|LINK
Hello:
Yes, I found a similar post last night after I had submitted this, and you are correct, changing the "Value" to "value" solves my problem. Thanks though!