Solved

Classic ASP - Help getting hidden value

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

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

830 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