Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2350
  • Last Modified:

Classic ASP - Help getting hidden value

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
JElster
Asked:
JElster
  • 2
  • 2
2 Solutions
 
Scott Fell, EE MVEDeveloperCommented:
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
 
JElsterAuthor Commented:
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
 
Scott Fell, EE MVEDeveloperCommented:
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
 
JElsterAuthor Commented:
Any way put the noteID in a session using JS and just call  Session("noteID");
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now