Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. writing to hidden input with javascript

writing to hidden input with javascript

Scheduled Pinned Locked Moved Web Development
csharpjavascriptsysadminquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jszpila
    wrote on last edited by
    #1

    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?

    P G 2 Replies Last reply
    0
    • J jszpila

      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?

      P Offline
      P Offline
      Paddy Boyd
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • J jszpila

        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?

        G Offline
        G Offline
        Guffa
        wrote on last edited by
        #3

        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; }

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups