Jump to content

Dropping Data Into A Hidden Field


Recommended Posts

In two separate dataforms I'm trying to do pretty much the same thing - and one works and the other doesn't!  I don't know what I'm doing wrong.

 

In my submission form, I have this:

 

<script>
 
function test(){
 
   var clientrate5 = parseFloat(document.getElementById("InsertRecordcustomer_rd5").value);
   var otarate5 = parseFloat(document.getElementById("InsertRecordotaH_rd5").value);
 
if (clientrate5 > otarate5) {
 
document.getElementById("InsertRecordotaH_rd5").style.background="lightpink";
document.getElementById("InsertRecordissue_5_h").value = 1;
 
}else{
document.getElementById("InsertRecordotaH_rd5").style.background="wheat";
document.getElementById("InsertRecordissue_5_h").value = 0;
}
}
document.getElementsByName("InsertRecordotaH_rd5")[0].onchange=test;
 
</script>
 
 
It works perfectly.  The issue_5_h field is a hidden field and depending upon the "if" it drops either a 1 or a 0 in the field.  Great.
 
 
Then in a Report / Details page, I have this:
 
<script type="text/javascript">
 
   var clientrate5 = '[@field:customer_rd5]';
   var otarate5a = '[@field:otaA_rd5]';
   var vdate5 = '[@field:date5]';
   var vota5a = '[@field:ota_heading_a5]';
   var issue5a = '[@field:issue_5_a]';
 
var statement5a = "On "+vdate5+", the "+vota5a+" rate ($"+otarate5a+") shows up lower than your rate ($"+clientrate5+")."
 
if (issue5a > 0) {
document.write(statement5a);
document.getElementById("EditRecordwi_5a").value =statement5a;
}
 
 
</script>
 
If the field is an active text field, it drops the statement into the field, no problem.  But it will not drop it into a hidden field.  Is this something that can only be done in a submission form?  Or am I doing something wrong?
 
Thanks in advance for any input!!

 

Link to comment
Share on other sites

Update:  Since both were dependent upon the same "if," I moved the building of the statement into the submission form and allowed it to write to the hidden field there.  Works perfectly.

 

I would still like the answer though!!  Is there something I need to do differently, to write to a hidden field in a detail datapage?

Link to comment
Share on other sites

Hello egilley,

 

According to your last question - hidden fields are hidden fields on any type of DataPages. Every time they translated to regular HTML elements (<input type="hidden" />)

 

According to your first question, I think there is some data type issue. Please pay your attention, that following code will create string variable, but not numeric

var issue5a = '[@field:issue_5_a]';

But below you are trying use it as numeric variable

if (issue5a > 0) { 

Please try change initialization of "issue5a" variable to following

var issue5a = Number('[@field:issue_5_a]'); 

Hope it will help.

 

Thanks

Link to comment
Share on other sites

kRv, thank you so much for your input, I appreciate you taking the time to give me feedback!!  In this particular case, it works as a numeric value, but you just helped me solve another problem!!  I was getting a NaN when creating a variable number to add to a static date - and so I used your suggestion and it works perfectly now!

 

Thank you!!

Link to comment
Share on other sites

Hello egilley,

 

I'm not sure what kind of issue you got with details DataPage, but quick example, which I create myself, works for me. Please see link to similar DataPage below

 

https://c2ebv261.caspio.com/dp.asp?AppKey=B4D840008d0048954b094c07a106

 

For make sure that we on same page, may you please post link to your DataPage? I will look on it, and will try figure out how I can help to you.

 

Thanks

Link to comment
Share on other sites

I'm still having the issue with not being able to save data into a hidden field - unless it's within a submission page, then it works fine.

 

Hi egilley,

 

Remember that in submission pages the fields are called "InsertRecordNameofyourField". When working with detail pages it would be "EditRecordNameofyourField". Have you tried referencing this way when using update pages??

Link to comment
Share on other sites

  • 2 weeks later...

kRv, I appreciate all the trouble you went to, to set up an example page for me but here I am almost two weeks later and I still have not solved this issue.  I'm so sorry, but I don't understand what you're showing me and how it will help me with the javascript and getting the statement I want to drop into a hidden field.  I have 156 fields and 156 statements and I can't have them all "showing" on the datapage I'm creating.  My boss wants them hidden and I can hide them on the submission page - but there is a limit to the size of each datapage and hiding them there put me past that limit.

 

douvega, I appreciate your help as well, but in the detail page it seems I can't use "EditRecordNameofField" unless the field is an active field within that datapage, meaning, again, that I would have to "show" all those fields.  The individual parts of this statement I need to save are already saved, so that's why I used "[@field:NameofField] instead.

 

If I make the target field an active text field rather than a hidden field, the whole thing works perfectly.  But if I make it hidden, it saves nothing.

 

<script>

 
   var clientrate1 = Number('[@field:customer_rd1]');
   var otarate1 = Number('[@field:otaA_rd1]');
   var date1 = '[@field:date1]';
   var otaheading1a='[@field:ota_heading_a1]';
   var statement1a="On "+date1+", the "+otaheading1a+" rate ($"+otarate1+") is lower than your rate ($"+clientrate1+").";
 
if (clientrate1 > otarate1) {
document.getElementById("EditRecordwi_1a").value = statement1a;
 
}
 
</script>
 
I've tried several ways, trying to work around this, and still have no answers.  I will be bald soon!
Link to comment
Share on other sites

Try moving the elements you want hidden down to the bottom of the page, leaving them active so your script can work on them. Then hide the results from displaying by wrapping the elements in HTML Blocks. Within the top HTML block put <table style = "display:none;"> then in the HTML block below the elements close the table statement with  </table> 
This should keep the elements between the HTML blocks from displaying, while keeping the text fields active for your JS operations.

Link to comment
Share on other sites

Hello egilley,

 

It is  a bit late, but I would like add some comments. 

 

>>I'm so sorry, but I don't understand what you're showing me and how it will help me with the javascript and getting the statement I want to drop into a hidden field

 

I did show to you example, which write something to hidden field if value in specified field meet some conditionals :) If you open details page for record with ID 1, nothing happened, because value of Int32 record equal zero. But if you will open any other records, you will see some message, generated via script. As I understand it is exactly what you would like to achieve. 

 

>>it seems I can't use "EditRecordNameofField" unless the field is an active field within that datapage

Excuse me, but it isn't correct. All DataPage's field, include all hidden fields, follow name convention described above. So, on Submission DataPage all customer's field have prefix InserRecord, and on Update\Details page all customer's fields have prefix EditRecord. There is only one exception - on Update\Details DataPage Display Only fields don't have input element at all, but they have it on Submission DataPage. Probably you got some another issue with script. 

   

Glad to see that your issue was resolved. May be this link also will helpful for you http://howto.caspio.com/datapages/forms/conditional-forms/

 

Thanks

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...