Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > accessing html input fields

Reply
Thread Tools

accessing html input fields

 
 
Jessica Weiner
Guest
Posts: n/a
 
      07-04-2006
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


 
Reply With Quote
 
 
 
 
Bart Van der Donck
Guest
Posts: n/a
 
      07-05-2006
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

 
Reply With Quote
 
 
 
 
marss
Guest
Posts: n/a
 
      07-05-2006

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"];
//.........
}

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
print struct fields and its member structs' fields recursively, generically call_me_anything C++ 4 09-30-2007 10:12 PM
Accessing input fields declared outside the form Jessica Weiner ASP .Net 2 07-05-2006 05:35 AM
accessing html fields Jessica Weiner ASP .Net Building Controls 1 07-05-2006 04:56 AM
accessing html fields Jessica Weiner ASP .Net Web Services 1 07-05-2006 03:08 AM
Create Dynamic Input Names or Input Fields in Asp gotcha ASP General 0 10-24-2003 10:41 PM



Advertisments