accessing html input fields

Discussion in 'Javascript' started by Jessica Weiner, Jul 5, 2006.

  1. I have an input field defined outside the <form> area. Its a simple html
    text input that is used to enter the number of hours.

    <input id="HoursField" name="hours" type="text" />

    I want to access this field from the server side (c# code). I tried these
    two methods to access the field but they dont work. Please help.

    String[] tempArray;
    tempArray = Request.Form.GetValues("hours");
    Response.Write (tempArray[0]);

    ---

    string val = Request.QueryString["hours"].ToString();
    Response.Write (val);


    Jessica
    Jessica Weiner, Jul 5, 2006
    #1
    1. Advertising

  2. Jessica Weiner wrote:

    > I have an input field defined outside the <form> area.


    By doing so, you don't pass the name/value pair of that <input> element
    to your gateway program, so there is no way to read it out. (but then,
    why on earth would one want to place it outside the form if you need it
    to reach the server?)

    > [...]


    Hope this helps,

    --
    Bart
    Bart Van der Donck, Jul 5, 2006
    #2
    1. Advertising

  3. Jessica Weiner

    marss Guest

    Jessica Weiner напиÑав:
    > I have an input field defined outside the <form> area. Its a simple html
    > text input that is used to enter the number of hours.
    >
    > <input id="HoursField" name="hours" type="text" />
    >


    If it absolutely necessary to place input out of the form you can
    achieve your goal by adding input field dinamically to the form
    directly before posting the form to the server.

    at client side:

    <script type=text/javascript>
    function SubmitHours()
    {
    document.forms[0].appendChild(document.getElementById('HoursField'));
    document.forms[0].submit();
    }
    </script>
    .....
    <input id="HoursField" name="hours" type="text" >
    <input type="button" value="Post Hours" onclick="SubmitHours()">
    .....


    at the server side in Page_Load:

    if (Request.Form["hours"] != null)
    {
    string s = Request.Form["hours"];
    //.........
    }
    marss, Jul 5, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jessica Weiner
    Replies:
    2
    Views:
    411
  2. Jessica Weiner

    accessing html fields

    Jessica Weiner, Jul 5, 2006, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    117
    ValliM
    Jul 5, 2006
  3. Jessica Weiner

    accessing html fields

    Jessica Weiner, Jul 5, 2006, in forum: ASP .Net Web Services
    Replies:
    1
    Views:
    115
    Scott M.
    Jul 5, 2006
  4. gotcha
    Replies:
    0
    Views:
    205
    gotcha
    Oct 24, 2003
  5. Replies:
    23
    Views:
    498
    Tim Streater
    Dec 18, 2013
Loading...

Share This Page