|
|
|
date: Mon, 23 Jan 2006 08:49:03 -0800,
group: microsoft.public.inetsdk.programming.scripting.jscript
back
Re: Pass value to hidden field
Ok ... and I guess I'm supposed to create a page called confirm.asp to check
whether the value of the hidden field got changed ... ?
In your original post, you said you were changing the value of the hidden
field AFTER the form was submitted. This code changes its value BEFORE
submission, so I guess that's what had me confused.
Let me go try and reproduce the behavior you are talking about.
Eric wrote:
> Here's a sample - appreciate your help.
>
> <form method="POST" name="ACH" onSubmit="return checkForm(this)"
> action="confirm.asp">
> <input type="hidden" name="save" value="">
> <input type="hidden" name="new_customer" value="">
> </form>
>
> <script language="javascript">
> function checkForm(ACH) {
> form = document.ACH
> if (form.new_customer.value != "yes") {
> var response = confirm ("To save typing in the future, do you
> wish to save\n this customer's account information?")
> //alert (response)
> if (response==true){
> form.save.value="yes";
> }
> }
> }
>
> "Bob Barrows [MVP]" wrote:
>
>> I'm a little confused. Could you create a small page that reproduces
>> this behavior and post it here?
>>
>> Eric wrote:
>>> I submit the form and it calls checkForm. If I hardcode a value
>>> into the hidden field and then do an alert, the value is displayed.
>>> I'm not submitting to a new window. The reason why I know the
>>> hidden value is not populated becuase I have some additional
>>> javascript validation which returns false, so I stay on the
>>> original page.
>>>
>>> "Bob Barrows [MVP]" wrote:
>>>
>>>> Eric wrote:
>>>>> I'm trying to populate a hidden input after a form is submitted.
>>>>
>>>> After submission?? Are you submitting to a new window?
>>>>
>>>>> Here's my code:
>>>>>
>>>>> function checkForm(ACH) {
>>>>> form = document.ACH
>>>>> if (form.new_customer.value != "yes") {
>>>>> var response = confirm ("To save typing in the future, do you
>>>>> wish to save\n this customer's account information?")
>>>>> //alert (response)
>>>>> if (response==true){
>>>>> form.save_cdb.value='yes';
>>>>> }
>>>>> }
>>>>>
>>>>> If I change the input type to 'text', the code works fine. But
>>>>> if I set the field to 'hidden' the value is not populated.
>>>>
>>>> How do you know? Hidden fields are not rendered on the screen and
>>>> programmatic changes to the DOM are ont reflected in the page's
>>>> Source. --
>>>> Microsoft MVP -- ASP/ASP.NET
>>>> Please reply to the newsgroup. The email account listed in my From
>>>> header is my spam trap, so I don't check it very often. You will
>>>> get a quicker response by posting to the newsgroup.
>>
>> --
>> Microsoft MVP -- ASP/ASP.NET
>> Please reply to the newsgroup. The email account listed in my From
>> header is my spam trap, so I don't check it very often. You will get
>> a quicker response by posting to the newsgroup.
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
date: Wed, 25 Jan 2006 08:31:04 -0500
author: Bob Barrows [MVP] com
Re: Pass value to hidden field
In order to reproduce your problem (didn't you test this?), I needed to
change the form to submit to itself and add a response.write to write in the
value of the submitted hidden field's value, like this:
<html><body>
<form method="POST" name="ACH" onSubmit="return checkForm(this)" action="">
<input type="hidden" name="save" value="<%=Request.Form("save")%>">
<input type="hidden" name="new_customer" value="">
<INPUT type="submit" value="Submit" id=submit1 name=submit1></form>
<script language="javascript">
function checkForm(ACH) {
form = document.ACH
if (form.new_customer.value != "yes") {
var response = confirm ("To save typing in the future, do you wish to
" +
"save\n this customer's account information?")
//alert (response)
if (response==true){
form.save.value="yes";
}
}
}
</script>
</body></html>
When I click the submit button and view the resulting page's source, I see:
<input type="hidden" name="save" value="yes">
So, it appears the hidden field's value is getting changed.
Again, why do you think that this is not occurring?
Eric wrote:
> Here's a sample - appreciate your help.
>
> <form method="POST" name="ACH" onSubmit="return checkForm(this)"
> action="confirm.asp">
> <input type="hidden" name="save" value="">
> <input type="hidden" name="new_customer" value="">
> </form>
>
> <script language="javascript">
> function checkForm(ACH) {
> form = document.ACH
> if (form.new_customer.value != "yes") {
> var response = confirm ("To save typing in the future, do you
> wish to save\n this customer's account information?")
> //alert (response)
> if (response==true){
> form.save.value="yes";
> }
> }
> }
>
> "Bob Barrows [MVP]" wrote:
>
>> I'm a little confused. Could you create a small page that reproduces
>> this behavior and post it here?
>>
>> Eric wrote:
>>> I submit the form and it calls checkForm. If I hardcode a value
>>> into the hidden field and then do an alert, the value is displayed.
>>> I'm not submitting to a new window. The reason why I know the
>>> hidden value is not populated becuase I have some additional
>>> javascript validation which returns false, so I stay on the
>>> original page.
>>>
>>> "Bob Barrows [MVP]" wrote:
>>>
>>>> Eric wrote:
>>>>> I'm trying to populate a hidden input after a form is submitted.
>>>>
>>>> After submission?? Are you submitting to a new window?
>>>>
>>>>> Here's my code:
>>>>>
>>>>> function checkForm(ACH) {
>>>>> form = document.ACH
>>>>> if (form.new_customer.value != "yes") {
>>>>> var response = confirm ("To save typing in the future, do you
>>>>> wish to save\n this customer's account information?")
>>>>> //alert (response)
>>>>> if (response==true){
>>>>> form.save_cdb.value='yes';
>>>>> }
>>>>> }
>>>>>
>>>>> If I change the input type to 'text', the code works fine. But
>>>>> if I set the field to 'hidden' the value is not populated.
>>>>
>>>> How do you know? Hidden fields are not rendered on the screen and
>>>> programmatic changes to the DOM are ont reflected in the page's
>>>> Source. --
>>>> Microsoft MVP -- ASP/ASP.NET
>>>> Please reply to the newsgroup. The email account listed in my From
>>>> header is my spam trap, so I don't check it very often. You will
>>>> get a quicker response by posting to the newsgroup.
>>
>> --
>> Microsoft MVP -- ASP/ASP.NET
>> Please reply to the newsgroup. The email account listed in my From
>> header is my spam trap, so I don't check it very often. You will get
>> a quicker response by posting to the newsgroup.
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
date: Wed, 25 Jan 2006 08:42:28 -0500
author: Bob Barrows [MVP] com
Re: Pass value to hidden field
I have additional validation occurring after I attempt to change the value of
the hidden value, so I return false in my code.
To apply this to the example, in my code,
just after 'form.save.value="yes";' I've added 'return false;' Sorry -
should have added this initially.
"Bob Barrows [MVP]" wrote:
> In order to reproduce your problem (didn't you test this?), I needed to
> change the form to submit to itself and add a response.write to write in the
> value of the submitted hidden field's value, like this:
> <html><body>
> <form method="POST" name="ACH" onSubmit="return checkForm(this)" action="">
> <input type="hidden" name="save" value="<%=Request.Form("save")%>">
> <input type="hidden" name="new_customer" value="">
> <INPUT type="submit" value="Submit" id=submit1 name=submit1></form>
>
> <script language="javascript">
> function checkForm(ACH) {
> form = document.ACH
> if (form.new_customer.value != "yes") {
> var response = confirm ("To save typing in the future, do you wish to
> " +
> "save\n this customer's account information?")
> //alert (response)
> if (response==true){
> form.save.value="yes";
return false;
> }
> }
> }
> </script>
> </body></html>
>
> When I click the submit button and view the resulting page's source, I see:
> <input type="hidden" name="save" value="yes">
>
> So, it appears the hidden field's value is getting changed.
> Again, why do you think that this is not occurring?
>
> Eric wrote:
> > Here's a sample - appreciate your help.
> >
> > <form method="POST" name="ACH" onSubmit="return checkForm(this)"
> > action="confirm.asp">
> > <input type="hidden" name="save" value="">
> > <input type="hidden" name="new_customer" value="">
> > </form>
> >
> > <script language="javascript">
> > function checkForm(ACH) {
> > form = document.ACH
> > if (form.new_customer.value != "yes") {
> > var response = confirm ("To save typing in the future, do you
> > wish to save\n this customer's account information?")
> > //alert (response)
> > if (response==true){
> > form.save.value="yes";
> > }
> > }
> > }
> >
> > "Bob Barrows [MVP]" wrote:
> >
> >> I'm a little confused. Could you create a small page that reproduces
> >> this behavior and post it here?
> >>
> >> Eric wrote:
> >>> I submit the form and it calls checkForm. If I hardcode a value
> >>> into the hidden field and then do an alert, the value is displayed.
> >>> I'm not submitting to a new window. The reason why I know the
> >>> hidden value is not populated becuase I have some additional
> >>> javascript validation which returns false, so I stay on the
> >>> original page.
> >>>
> >>> "Bob Barrows [MVP]" wrote:
> >>>
> >>>> Eric wrote:
> >>>>> I'm trying to populate a hidden input after a form is submitted.
> >>>>
> >>>> After submission?? Are you submitting to a new window?
> >>>>
> >>>>> Here's my code:
> >>>>>
> >>>>> function checkForm(ACH) {
> >>>>> form = document.ACH
> >>>>> if (form.new_customer.value != "yes") {
> >>>>> var response = confirm ("To save typing in the future, do you
> >>>>> wish to save\n this customer's account information?")
> >>>>> //alert (response)
> >>>>> if (response==true){
> >>>>> form.save_cdb.value='yes';
> >>>>> }
> >>>>> }
> >>>>>
> >>>>> If I change the input type to 'text', the code works fine. But
> >>>>> if I set the field to 'hidden' the value is not populated.
> >>>>
> >>>> How do you know? Hidden fields are not rendered on the screen and
> >>>> programmatic changes to the DOM are ont reflected in the page's
> >>>> Source. --
> >>>> Microsoft MVP -- ASP/ASP.NET
> >>>> Please reply to the newsgroup. The email account listed in my From
> >>>> header is my spam trap, so I don't check it very often. You will
> >>>> get a quicker response by posting to the newsgroup.
> >>
> >> --
> >> Microsoft MVP -- ASP/ASP.NET
> >> Please reply to the newsgroup. The email account listed in my From
> >> header is my spam trap, so I don't check it very often. You will get
> >> a quicker response by posting to the newsgroup.
>
> --
> Microsoft MVP -- ASP/ASP.NET
> Please reply to the newsgroup. The email account listed in my From
> header is my spam trap, so I don't check it very often. You will get a
> quicker response by posting to the newsgroup.
>
>
>
date: Wed, 25 Jan 2006 06:15:03 -0800
author: Eric
Re: Pass value to hidden field
Eric wrote:
> I have additional validation occurring after I attempt to change the
> value of the hidden value, so I return false in my code.
> To apply this to the example, in my code,
> just after 'form.save.value="yes";' I've added 'return false;'
> Sorry - should have added this initially.
>
OK, so that prevents the form from being submitted. So where are you
checking the value of the save input? Again, it will not be reflected in
View Source, which never changes due to programmatic changes to page
elements.
Let's add a button to cause an alert of the value of the save input:
<html><body>
<form method="POST" name="ACH"
onSubmit="return checkForm(this)" action="">
<input type="hidden" name="save" value="<%=Request.Form("save")%>">
<input type="hidden" name="new_customer" value="">
<INPUT type="submit" value="Submit" id=submit1 name=submit1>
<INPUT type="button" value="What's the value of save?"
onclick="alert(form.save.value);">
</form>
<script language="javascript">
function checkForm(ACH) {
form = document.ACH
if (form.new_customer.value != "yes") {
var response = confirm ("To save typing in the future, do you wish to
" +
"save\n this customer's account information?")
//alert (response)
if (response==true){
form.save.value="yes";
return false;
}
}
}
</script>
</body></html>
From what I can see, the value of the save field is definitely being changed
....
Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
date: Wed, 25 Jan 2006 09:54:11 -0500
author: Bob Barrows [MVP] com
Re: Pass value to hidden field
Yes, I was using 'view source' to check the value. So you're saying the
value doesn't get changed unless the form is actualy submitted? Why is it
that if I run the same code, but change the hidden to text, it will change
the value?
Im sure there's another way to achieve my goal, but I was grappling w/this
and needed some input for someone else.
Again, thanks for your help!
"Bob Barrows [MVP]" wrote:
> Eric wrote:
> > I have additional validation occurring after I attempt to change the
> > value of the hidden value, so I return false in my code.
> > To apply this to the example, in my code,
> > just after 'form.save.value="yes";' I've added 'return false;'
> > Sorry - should have added this initially.
> >
> OK, so that prevents the form from being submitted. So where are you
> checking the value of the save input? Again, it will not be reflected in
> View Source, which never changes due to programmatic changes to page
> elements.
>
> Let's add a button to cause an alert of the value of the save input:
>
> <html><body>
> <form method="POST" name="ACH"
> onSubmit="return checkForm(this)" action="">
> <input type="hidden" name="save" value="<%=Request.Form("save")%>">
> <input type="hidden" name="new_customer" value="">
> <INPUT type="submit" value="Submit" id=submit1 name=submit1>
> <INPUT type="button" value="What's the value of save?"
> onclick="alert(form.save.value);">
> </form>
> <script language="javascript">
> function checkForm(ACH) {
> form = document.ACH
> if (form.new_customer.value != "yes") {
> var response = confirm ("To save typing in the future, do you wish to
> " +
> "save\n this customer's account information?")
> //alert (response)
> if (response==true){
> form.save.value="yes";
> return false;
> }
> }
> }
> </script>
> </body></html>
>
> From what I can see, the value of the save field is definitely being changed
> ....
>
> Bob Barrows
> --
> Microsoft MVP -- ASP/ASP.NET
> Please reply to the newsgroup. The email account listed in my From
> header is my spam trap, so I don't check it very often. You will get a
> quicker response by posting to the newsgroup.
>
>
>
date: Wed, 25 Jan 2006 07:08:02 -0800
author: Eric
Re: Pass value to hidden field
Eric wrote:
> Yes, I was using 'view source' to check the value. So you're saying
> the value doesn't get changed unless the form is actualy submitted?
No. I am saying the value changes, but the change is not reflected in the
page's source. The alert(form.save.value) proves this does it not?
The only thing client-side code (DHTML) can change is the result that is
rendered in the browser window.
> Why is it that if I run the same code, but change the hidden to text,
> it will change the value?
It does not change it in Source does it? Because the text element is
rendered on the screen, the change in its value is reflected on the screen,
i.e., in the browser window. But if you View Source, you will see that the
Source is unchanged.
> Im sure there's another way to achieve my goal,
I'm not sure what your goal is.
If your goal is to cause a change to the page's source in client-side code,
then that is not possible. I'm not even sure why you would need this to
happen.
If your goal is to cause a change to the hidden field's value, which can be
seen and checked by the page to which you are submitting the form, then your
goal is achieved. This is proven by removing the "return false;" statement
and seeing the result of <%=Request.Form("save")%> in the responding page
using View Source.
Only server-side code can modify the html (what is seen in View Source) sent
to the browser.
Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
date: Wed, 25 Jan 2006 10:38:03 -0500
author: Bob Barrows [MVP] com
|
|