writing to hidden input with javascript
-
Hello all, I'm using a vb.net function to write some javascript to a literal control. That part works just fine. However, the javascript I'm writing is supposed to write the return value of a confirmation dialogue to a hidden input to reference later. I can reference the hidden input fine, but it always contains the default value - it seems that the javascript never writes to it. Here's my hidden field and literal control: <asp:Literal id="ltAlert" runat="server" EnableViewState="false" /> Here's my vb function: Function GetConfirmation(ByVal strVerb As String) As Sring ltAlert.Text = "document.getElementById('hdnbox').value = window.confirm('Are you sure you want to " & strVerb & " these requests?');" Return hdnbox.Value.ToString() End Function It always returns "hello!", instead of the true or false that one would expect. It has to be something really tiny and stupid that I'm looking right over. Note I've also tried variations along the lines of var answer = window.confirm("blah"); document.getElementById('hdnbox') = answer; to no avail. Also worthy of note it seems to be returning the value before the user has had the chance to interact with the dialogue. Any ideas? Thanks in advance! ------------------- abort, retry, fail?
-
Hello all, I'm using a vb.net function to write some javascript to a literal control. That part works just fine. However, the javascript I'm writing is supposed to write the return value of a confirmation dialogue to a hidden input to reference later. I can reference the hidden input fine, but it always contains the default value - it seems that the javascript never writes to it. Here's my hidden field and literal control: <asp:Literal id="ltAlert" runat="server" EnableViewState="false" /> Here's my vb function: Function GetConfirmation(ByVal strVerb As String) As Sring ltAlert.Text = "document.getElementById('hdnbox').value = window.confirm('Are you sure you want to " & strVerb & " these requests?');" Return hdnbox.Value.ToString() End Function It always returns "hello!", instead of the true or false that one would expect. It has to be something really tiny and stupid that I'm looking right over. Note I've also tried variations along the lines of var answer = window.confirm("blah"); document.getElementById('hdnbox') = answer; to no avail. Also worthy of note it seems to be returning the value before the user has had the chance to interact with the dialogue. Any ideas? Thanks in advance! ------------------- abort, retry, fail?
Both of these seem to have errors, have you tried debugging through them: Or try these:
document.getElementById('hdnbox').value = window.confirm('Are you sure you want to " & strVerb & " these requests?');"
or
var answer = window.confirm("blah");
document.getElementById('hdnbox').value = answer;-- modified at 4:07 Tuesday 25th July, 2006
-
Hello all, I'm using a vb.net function to write some javascript to a literal control. That part works just fine. However, the javascript I'm writing is supposed to write the return value of a confirmation dialogue to a hidden input to reference later. I can reference the hidden input fine, but it always contains the default value - it seems that the javascript never writes to it. Here's my hidden field and literal control: <asp:Literal id="ltAlert" runat="server" EnableViewState="false" /> Here's my vb function: Function GetConfirmation(ByVal strVerb As String) As Sring ltAlert.Text = "document.getElementById('hdnbox').value = window.confirm('Are you sure you want to " & strVerb & " these requests?');" Return hdnbox.Value.ToString() End Function It always returns "hello!", instead of the true or false that one would expect. It has to be something really tiny and stupid that I'm looking right over. Note I've also tried variations along the lines of var answer = window.confirm("blah"); document.getElementById('hdnbox') = answer; to no avail. Also worthy of note it seems to be returning the value before the user has had the chance to interact with the dialogue. Any ideas? Thanks in advance! ------------------- abort, retry, fail?
Do you expect the VB function to return anything other than the string "hello!"? That will never happen. It's not something really tiny you have overlooked. You are apparently confused on the whole concept of how a web page is created on the server and handled in the browser. First the source code for the page is created on the server. At this point the javascript code is just treated as text by the server. When the page is complete, the server code ends, and the pave is sent to the browser. The browser will then show the page and run the javascript. Consider these two rules: 1. The server side code and the client side code never exist in the same place. 2. The server side code and the client side code never exist at the same time. If you want to send anything back to the server, you have to send it in a new request, so that the server code is started again.
--- b { font-weight: normal; }