How to get value of hidden field inside a form using onSubmit function?

 In the form, there are some forms which structures look like this:

    <form action="/catalog/" method="GET" onSubmit="WriteCategoryIDToCookie()">
        <input type="hidden" name="product_id" value="8400010">       
    <input type="Image" name="add_to_cart" src="/i/style/def/btn/bp_cart_btn_med.gif" alt="Add to Cart">

I insert onSubmit function named WriteCategoryIDToCookie(). In this function, I need to get the value of hidden field inside this form. Is there any way to do it? It is easier if there is only one form in page. However, there are several forms like this.

Please help me. Thank in advance. 

3/19/2008 9:11:52 AM 24353 articles. 2 followers. Follow

4 Replies

Similar Articles

[PageSpeed] 53

You could use:


or if you give each form an id then you could use something like:



To make it more robust you might want to check the "product_id" element isn't null before getting it's value, e.g.

    var myField = document.getElementById("product_id");
    if(myField != null)




"Sometimes I think the surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact us."
3/19/2008 10:19:22 AM

Pass "this" word to your function:


    <form action="/catalog/" method="GET" onSubmit="WriteCategoryIDToCookie(this)">
        <input type="hidden" name="product_id" value="8400010">        


function WriteCategoryIDToCookie(form)





May the Force be with you
3/19/2008 10:22:15 AM

Yes, passing the form object in using 'this' is much neater! You should probably still check that product_id is a valid element of the form before trying to use it though Smile

"Sometimes I think the surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact us."
3/19/2008 10:28:53 AM

 Thank you very much for your help.

3/20/2008 1:23:12 AM

Similar Artilces:

Use client side code to get hidden field value from calling page
Hi, I have a web application that is being called from an extranet app. I need to access the value of a hidden form variable on the calling form, I have tried Request.form("Fieldname") & cannot pick up any values. They are not keen on passing the value in the querystring - I would really appreciate some help on this. Thanks If the item is not in the form collection, then they're probably not doing a POST to your page. You can pass information to a page three ways: URL (querystring, fragment, etc), POST (form.submit()), and via a HTTP Header. They'll need to decide...

Using hidden field to store value then calling that value from client side
I have three tabs (1,2,3) on my main page each tab contains a datagrid... when a user select a tab then leaves the main page and returns to that main page(without exiting browser) I need for the page to open with the tab last selected by that user so that they can pick up where they left off. No one can seem to help me with this issue.... My javascript (client side) code function is as follows: <asp:HiddenField ID="hdnNewPanel" runat="server" /> <script language="javascript" type="text/javascript"> &nb...

Hidden Field that is set on server side...not getting the last updated value from client?
Hi, I have a hidden field that tracks errors in my server side 2.0 code.  However, when I set the value to an error (from it's default value "NotSet") in the server side code and then when trying to access that Hidden Variable from the client the value is still set to the default value, "NotSet" instead of the error information. Any ideas as to what is going on here? Thanks in advance!   Server Side....  catch (Exception er) { Errors.Value = er.Message; o o o } Client Side.... function getErrors() { var cho = document.getElementById('<%=Errors.ClientID...

Getting hidden variable value from server side in client side
hi,        I am struck in problem. I have a hidden field in my form and i am setting some value in that.         Now i wnt to use this value from client side but i m not able to retrieve it. All i am getting there is an object.         I feel the hidden field is not able to hold that value.         <input type="hidden" id="hdnVar" runat="server" />         in code behind      ...

Passing client side to server side using hidden field
 I have a hidden text box that is being updated on the client via javascript. I am trying to determine the best way to detect when that hidden field has changed and read the new value on the server. I would like to do this WITHOUT posting back. I have tried using the TextChanged event but that requires blur state to be changed before it gets fired. What would be the best way to do this? Thanks, Justin.  Can you use __doPostBack() to trigger a partial postback at the same time the hidden TextBox is updated, from JavaScript? Encosia - ASP.NET, AJAX, and more.Lates...

pls help: how to get client-side HTML "text field" value from a server side button
i copy some javascript from somewhere so user can choose pick up a date from a calendar and display the date onto a HTML text field. I have no knowledge in writing client side script(i.e. write code in html) can i write some code in a server-side button to get the value in the HTML text field??? i tried: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click textbox1.text = document.getElementById("htmltext").value End Sub but "document" is highlighted, and say isn't declar yet. and...

Getting values from form fields and use them in a query...
Hello all, I'm a newbie in ASP .NET, Visual Studio .NET, C# and VB .NET so please bear with me if you find this question so "beginner" or stupid. I badly need to know how to get the value from a data form field and use it as an argument in an SQL query. I was used to manipulating form values in HTML that I somehow find it hard to shift to VB or C#. I don't know how to do this in a code-behind in VS using C# with Access as my database. If you could just direct me to a tutorial or link that will help/teach me in using VS forms inside ASP code-behinds or stuff like that so I amy ...

Getting Value from Client-side InputBox to .net variable
hi, im doing a login page for our timekeeping. Since there's no msgbox available on, im doing it dynamically via javascript. How do i Get the value frm a dynamically written javascript (such as inputbox) to a .net variable? here's the logic of my program, user logs in hits the button and sub-routine Login will be fired, if user is late -- call Check_Late Sub, this is whre the client-side script was built -- then after that i wanted to be able to get the value from an inputbox. '// if button login clicked Sub Login(Sender As Object, E As EventArgs) .......

Get field value from DataRow or DataTable for use in function
Hi All, Something I thought was simple is proving to be a challenge in taking a recordset from a DB and looping foreach into a function :SqlConnection cn = new SqlConnection(connectionString);string sCommand = "SELECT [emailadd], [recID] FROM [md_temppers]"; SqlDataAdapter da = new SqlDataAdapter(sCommand, cn);DataTable dataTable = new DataTable();MembershipCreateStatus status;         try                 {             ...

Get the Dropdownlist text and value using Javascript from client side
Hi, I am encountering a problem about how to get the Dropdownlist text and value using Javascript from client side. I am using C# in Visual Studio 2005 and Javasript . The example codes are like: ( In this example code, I would like to access the text and value of the DropDownListReports in the run() function of Javascript. How can I do that? Any ideas? Thanks a lot. ) protected void Page_Load(object sender, EventArgs e) {              if (!Page.IsPostBack)            &nb...

Client side set hidden field value not POSTing back
 hi,(sorry, I dont have any code snippets to hand as I'm away from the dev machine at the mo)I have a page which makes two seperate WebServce calls for data. One is via an Ajax call, the other is server side.The flow is as follows:1. Ajax Web Service call returns a collection2. In the js script file, read the PK's of the collection and set a hiddenfield with the comma-seperated keys3. initiate a __doPostBack call from script - target an update panel on the page which then calls the second Web ServiceThe problem I am experiencing is that after I have made the first call and ...

Change hidden field value on client side, then retrieve on serverside
I am trying to change a hidden field's value on the client side with Javascript, then retrieve it after postback.The hidden field is inside a user control. The user control's containing page attempts to access the hidden field's value in a click event handler, but the hidden field's value still has the old value.However, by the user control's prerender phase the hidden field does contain the new value.I notice that if I use Request.Form, the same behaviour is exhibited.How can I retrieve the hidden field's new value, without having to wait for the prerender stage. Or alternatively, how can I...

Hidden field client side value lost on post back
Hi, I have a checkbox list , two text box , with link to javascript calendars and two hidden fields. The checkbox list contains years with start and end date in text part and the two textboxes are From and To date. Initially when the page is loaded the first year in the list is checked then the hidden field for start and end date is set at server side. After that on client side onload we run a javascript that picks up the date from hidden fields and set them on the two dates textboxex respectively in client locale. No when i change the checkbox check the repect date in text part of the ...

Issue obtaining values in server-side from dropdownlist when updating value using client-side script in master page
HiI got a page in a contentplaceholder of a master page. There is two pulldowns. I populate the first one using server side coding and then use client-side javascript. So far so good. The issue is that upon a postback I try to collect the select value of the second pulldown and there is no data in the pulldown and no selected item. I tried using control.selectedvalue (nothing) or searching the form controls Stringvariable = oForm.FindControl("Control")Thing is I've done this before in 1.1 outside of a master page and it works.Thanks in ad...

Web resources about - How to get value of hidden field inside a form using onSubmit function? -

Wave function - Wikipedia, the free encyclopedia
... (a ball attached to a spring ) in classical mechanics (A-B) and quantum mechanics (C-H). In quantum mechanics (C-H), the ball has a wave function ...

TV binging, exercise skipping linked to poor cognitive function
... their fit, less TV-addicted counterparts. In particular, couch potatoes had slightly lower brain processing speeds and worse executive function, ...

iPhone best tricks and functions - Business Insider
Your iPhone can do a lot more than you think.

Facebook Updates Search Function; Now Is A Great Time To Run And Check All Your Privacy Settings
Facebook search is… well, kind of a joke. It can tell you which 400 people in your area have similar names to that one person you want to connect ...

Review: HP Spectre 360 A Perfect Mix Of Style, Form, Function
HP Inc. delivers a brushed-aluminum laptop with a new 6th Generation Intel i7 processor, making it one of the best-looking, best-priced and best-performing ...

Why Global Corporations Need To Redesign Their Strategic Planning Function
Corporate strategy teams play an important role in guiding business leaders to make smarter, better and more informed decisions, especially in ...

Sponsored post: Garmin’s fenix 3 Pairs Form and Function with GPS Watch
... timepiece to polish off a professional look, or strap on a rugged stopwatch for our workouts. But when it comes to everyday use, the functional ...

Code Craft – Embedding C++: Timing Virtual Functions
... compiler just like the standard language types. A subtype inherits the characteristics of its parent type and can use, or not, the member functions ...

Madras HC asks police to allow Tipu’s birth anniversary function
... Station on a petition filed by Ismail, General Secretary of Thamizhaga Makkal Jananayaga Katchi, seeking grant of permission to hold the function. ...

Colorado governor: This Planned Parenthood shooting may be a function of inflammatory rhetoric from bloggers ...
Via Grabien , skip to 4:45 of the clip below for the key bit. I naively thought we were (mostly) done with “climate of hate” stupidity after ...

Resources last updated: 12/4/2015 3:42:52 AM