Classic ASP - Help getting hidden value

Posted on 2014-07-31
Last Modified: 2014-08-04
I have a hidden value on a page.

    <input type="hidden" name="noteId" id="noteId"/>

I can 'see' the value in the HTML.   Next I need to get that value to run a query.
But the following next line is always null


' Run query based on noteId HERE


Any ideas what I am doing wrong?

Question by:JElster
  • 2
  • 2
LVL 52

Assisted Solution

by:Scott Fell, EE MVE
Scott Fell,  EE MVE earned 150 total points
ID: 40231569
You have to submit a form to get request.form to work.    If the field and request.form are on the same page and nothing is submitted it will not work.

You can use javascript or jquery to get a value on the page without submitting a form.  Can you post your code or link to your sample?

Author Comment

ID: 40231618
It's as simple as this...   How can I get the value in Jquery and pass it to the query below?

    <input type="hidden" name="noteId" id="noteId"/>

                   <!-- Get Current Note Record -->
                       if NOT(IsNull(request.form("noteId")) or request.form("noteId")="") then
                            strSql = "SELECT * FROM NOTES WHERE NOTEID = " + request.form("noteId")

LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 40231650
You can't do that directly with javascript/jquery.  I do see an issue with your if statement.

   if NOT(IsNull(request.form("noteId")) or request.form("noteId")="") then

should be

   if NOT(IsNull(request.form("noteId")) AND request.form("noteId")<>"") then

Is a form being submitted here? or do you need to use the value that is typed into   <input type="hidden" name="noteId" id="noteId"/>?  If that is the case, we need to use ajax where we use javascript/jquery to grab the value entered and submit to another asp page, grab the output and bring it to the current page or redirect to another.

Author Comment

ID: 40231789
Any way put the noteID in a session using JS and just call  Session("noteID");
LVL 32

Accepted Solution

Big Monty earned 350 total points
ID: 40231895
Any way put the noteID in a session using JS and just call  Session("noteID");

yes, but you still need to post the data back to the server. once an http page loads, all forms of communication are done, the exception being when you use ajax, which I'm not sure would be appropriate here

to do what you want, you have to SUBMIT the value back to the server as was mentioned previously. you're on the right track with your code, you just need to allow for the value of noteID to be set (how will the hidden variable noteID be set?). you could do something like this:

         '-- Get Current Note Record
       '-- changed your IF statement to this way as you cannot post NULL values, only blank values, so the original IF statement was redundant        
      if Len( Request.Form("noteID") ) > 0 then                       
            dim noteID: noteID = Request.Form("noteID")

            '-- make sure we have a valid value for noteID
            if noteID = "" or not isNumeric( noteID ) then noteID = 0

           strSql = "SELECT * FROM NOTES WHERE NOTEID = " & noteID

       end if

<form name="frm1" id="frm1" method="post" action="thisPage.asp" >
    <input type="hidden" name="noteId" id="noteId" value="12345" />
    <button type="submit">Submit Hidden Variable NoteID</submit>

Open in new window

this is a very simple page to show you how to do what you're asking. copy and paste this into an asp page, run it, and you'll see the button. Once you click it, you will see the sql with a noteID value of 12345, which is a value I hard-coded as an example.

Any questions, please let us know.

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: and…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now