Solved

Classic ASP - Help getting hidden value

Posted on 2014-07-31
5
1,635 Views
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

<%
   Response.write(request.form("noteId"))

' Run query based on noteId HERE

%>

Any ideas what I am doing wrong?

thx
0
Comment
Question by:JElster
  • 2
  • 2
5 Comments
 
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?
0
 
LVL 1

Author Comment

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

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

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

                          'Test
                            Response.write(strSql)
0
 
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.
0
 
LVL 1

Author Comment

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

Accepted Solution

by:
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

           Response.write(strSql)
       end if

%>
<html>
<head></head>
<body>
<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>
</form>
</body>
</html>

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.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
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 is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

932 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