Help: Hidden value missing in request.form

J

J. Alan Rueckgauer

I have an <input type="hidden"> on a form that has its .value set in
client-side script called from another asp in an <iframe> on that page.
When the form is posted back to the server, the field shows as being in the
form items collection, but the value is an empty string. The other <input>s
from the form seem fine.l I know the value is actually arriving in the
client because it displays both as the .innerHTML of a <td> and in
View|Source.

**********
(client page)
<script language="vbscript">
sub GotRecord(byval TheRecIdent, byval TheNameInfo, byval TheShowRecFlag)
myform.hiddenRecIdent.value = TheRecIdent
tdIdent.innerHTML = "ID: " & myform.hiddenRecIdent.value
tdNameInfo.innerHTML = TheNameInfo
if TheShowRecFlag = "1" then
myform.chkShowInfoFlag.checked = true
else
myform.chkShowInfoFlag.checked = false
end if
rowNameInfo.style.visibility = "visible"
rowEditArea.style.visibility = "visible"
end sub
....
</script>
....
<form name="myform" action="page_proc.asp" method="post"
target="ifrmPlaypen">
<input type="hidden" name="hiddenRecIdent"
value="<%=session("CurrentRecIdent")%>">
<table width="100%" id="table2">
<tr>
<td id="tdIdent"><input type="text" name="txtRecIdent"
size="20"><input type="submit" value="Get" name="B1"></td>
</tr>
<tr id="rowNameInfo" style="visibility:hidden">
<td id="tdNameInfo">&nbsp;</td>
</tr>
<tr id="rowEditArea" style="visibility:hidden">
<td><input type="checkbox" name="chkShowInfoFlag" value="ON" <% if
session("CurrentRecIsVisibleFlag") = 1 then %>CHECKED<% end if %>>Include
this person in searches</td>
</tr>
</table>
<p><p align="center"><input type="submit" value="Save Changes"
name="B2"></p>
</form>
**********
(server script)
<%
... (irrelevant stuff omitted)
set TheForm = request.form
with TheForm
strPageAct = ucase(.Item("B1"))
if strPageAct = "" then
strPageAct = ucase(.Item("B2"))
end if
if instr(strPageAct, "GET") > 0 then
session("DoWhat") = "GET"
strRecIdent = Trim(.Item("txtRecIdent"))
elseif instr(strPageAct, "SAVE") > 0 then
' it knows that B2 was what caused the submit
IsPostBack = True
session("DoWhat") = "SAVE"
strRecIdent = .Item("hiddenRecIdent") '<== HERE'S WHERE THINGS
GO WRONG
' hiddenRecIdent.value never shows up
end if
end with
If strRecIdent > "" Then
Set TheAttendee = New clsAttendee
TheAttendee.GetByRegistration(strRecIdent)
With TheAttendee
If .AttendeeID = strRecIdent Then
If strPageAct = "GET" Then
session("CurrentRecIdent") = .AttendeeID
session("CurrentNameInfo") =
replace(.ContactInfoBlock(True), vbCrLf, "")
session("CurrentRecIsVisibleFlag") = .RecordStatus
ElseIf strPageAct = "SAVE" Then
' do the stuff to save the changes
End If
Else
' **** strRecIdent is always ""
session("ProcMsg") = "The AttendeeID didn't make it from the
form."
End If
%>
<html>
<head>
<SCRIPT language="VBScript">
sub Window_onload
dim huh, duh
huh = "<%=session("DoWhat")%>"
select case huh
case "GET"
window.parent.GotRecord "<%=session("CurrentRecIdent") %>",
"<%=session("CurrentNameInfo")%>", "<%=session("CurrentRecIsVisibleFlag")%>"
case "SAVE"
duh = "<%=session("ProcMsg")%>"
if duh = "" then
duh = "Record has been updated."
window.parent.RecSuccess duh
else
window.parent.RecFailed duh
end if
end select
end sub
</script>
</head>
<body>
Action: <%=strPageAct%><br>
DoWhat: <%=session("DoWhat")%><br>
Registration: <%=strRecID%></br>
Result: <%=session("ProcMsg")%><br>
<% if session("DoWhat") = "SAVE" then %>
Form Contents dump:<br>
<%
dim x
for each x in Request.Form
Response.Write("<br>" & x & " = " & Request.Form(x))
next
%>
<% end if %>
</body>
</html>
**********

So, any ideas why the hidden field's value never comes across in the POST,
even though the client sees it fine?

Thanks mucho in advance...

Alan
 
B

Bob Barrows

J. Alan Rueckgauer said:
I have an <input type="hidden"> on a form that has its .value set in
client-side script called from another asp in an <iframe> on that
page. When the form is posted back to the server, the field shows as
being in the form items collection, but the value is an empty string.
The other <input>s from the form seem fine.l I know the value is
actually arriving in the client because it displays both as the
.innerHTML of a <td> and in View|Source.
So, any ideas why the hidden field's value never comes across in the
POST, even though the client sees it fine?

Thanks mucho in advance...

Alan

I created a test page with this html:
<form name="myform" action="page_proc.asp" method="post"
target="ifrmPlaypen">
<input type="hidden" name="hiddenRecIdent"
value="test">
<table width="100%" id="table2">
<tr>
<td id="tdIdent"><input type="text" name="txtRecIdent"
size="20"><input type="submit" value="Get" name="B1"></td>
</tr>
<tr id="rowNameInfo" style="visibility:hidden">
<td id="tdNameInfo">&nbsp;</td>
</tr>
<tr id="rowEditArea" style="visibility:hidden">
<td><input type="checkbox" name="chkShowInfoFlag" value="ON" >Include
this person in searches</td>
</tr>
</table>
<p><p align="center"><input type="submit" value="Save Changes"
name="B2"></p>
</form>

And put this code in page_proc.asp:
<%
for each x in Request.Form
Response.Write x & ": """ & Request.Form(x) & """<BR>"
next
%>

And got this result:
hiddenRecIdent: "test"
txtRecIdent: "text that I entered"
B2: "Save Changes"

You do realize that by using client-side vbscript that you are limiting your
users to those with IE ...

Anyways, try this in the form's onsubmit event:
alert(myform.hiddenRecIdent.value)

Bob Barrows
 
J

J. Alan Rueckgauer

I created a test page with this html:
<snip>

Bob --

Thanks for the response. I'm not encountering the problem if the value of
the hidden field's value is established by <%=...%> or as an in-line
literal - only if the value is altered in script after it has been set
initally.

What I'm trying to do is combine an existing series of pages into two...the
existing flow is a page to collect the desired record id, then a server
script that fetches the record, then the page that displays the info, which
invokes the "*_proc.asp" page, and lastly a "results" page. The hidden
field is populated by a <%=session(...)%> value and all is happy. The new
"combined" page first displays the input for the record id. B1 gets clicked
and it posts to the proc script, which pulls the identifier from the <input
type="text" name="txtRecIdent">, does the lookup, stuffs some results into
session variables, then calls the script in the client to let it know the
results. The client script replaces the value of the hidden field with the
record identifier (if there was a hit), replaces the input prompt cell with
the identifier, shows a static text block representation of the current
info, then makes the table row containing the editable fields visible. If
there are changes, user clicks B2 ("Save Changes"), which posts back to the
same proc script where it sees B2 was the submit button, and looks for the
value in our hidden guy to figure out what record to update.

What has me stumped is why it fails if the hidden field is changed by
script. Just to add a bit more detail, the server is Win2K, SP4, .Net
Framework 1.1.4322.573 (though this is just classic ASP), and is completely
current on updates. All the client machines are XP Pro, SP1, same .Net,
also all completely up to date on patches.
You do realize that by using client-side vbscript that you are limiting your
users to those with IE ...

Yup. This is for an intranet where everyone is using IE6...no need to worry
about non-MS browsers.
Anyways, try this in the form's onsubmit event:
alert(myform.hiddenRecIdent.value)
I also did this, and the value does show correctly on the client side. When
I dismiss the alert and it hits the server, presto, it's gone.

Grrrrrrr. Why on a Monday?

Any other suggestions for things to look at?

Thanks,
Alan
 
B

Bob Barrows

J. Alan Rueckgauer said:
<snip>

Bob --

Thanks for the response. I'm not encountering the problem if the
value of the hidden field's value is established by <%=...%> or as an
in-line literal - only if the value is altered in script after it has
been set initally.

OK, so I added this:

<SCRIPT ID=clientEventHandlersVBS LANGUAGE=vbscript>
Sub myform_onsubmit
myform.hiddenRecIdent.value = "set by onsubmit event"
End Sub
</SCRIPT>

When I submit the form, I get this:
hiddenRecIdent: "set by onsubmit event"
txtRecIdent: "entered by me"
B2: "Save Changes"

and when I click the Get button, this is what I get:
hiddenRecIdent: "set by onsubmit event"
txtRecIdent: "entered by me"
B1: "Get"

I've looked again at your original post - I don't see anything calling that
GotRecord sub. That could be your problem...

Bob Barrows
 
J

J. Alan Rueckgauer

I've looked again at your original post - I don't see anything calling that
GotRecord sub. That could be your problem...
<snip>

Bob --

GotRecord is called from the Window_onload sub in the server script file
(it's in the <head>, towards the end of what I originally posted). The call
is: window.parent.GotRecord "<%=session("CurrentRecIdent") %>",
"<%=session("CurrentNameInfo")%>",
"<%=session("CurrentRecIsVisibleFlag")%>". It is definitely being invoked
because if it weren't, the main form would never get the record to display,
or show it, or make B2 visible.

(Remember, the proc script is being invoked in an <iframe> target. The
GotRecord call is executed after the server-side code finishes the record
lookup and has populated the session variables. The proc page's <iframe> is
normally hidden and the display code is only there for debugging.)

Alan
 
B

Bob Barrows

J. Alan Rueckgauer said:
<snip>

Bob --

GotRecord is called from the Window_onload sub in the server script
file (it's in the <head>, towards the end of what I originally
posted). The call is: window.parent.GotRecord
"<%=session("CurrentRecIdent") %>", "<%=session("CurrentNameInfo")%>",
"<%=session("CurrentRecIsVisibleFlag")%>". It is definitely being
invoked because if it weren't, the main form would never get the
record to display, or show it, or make B2 visible.

(Remember, the proc script is being invoked in an <iframe> target.
The GotRecord call is executed after the server-side code finishes
the record lookup and has populated the session variables. The proc
page's <iframe> is normally hidden and the display code is only there
for debugging.)
Oh! Was that all one page?

Bob Barrows
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top