Compu Posted April 22, 2014 Report Share Posted April 22, 2014 Trying to get a script to work on a single record update forum to update a field based on a dropdown value and can't figure out what I'm doing wrong. Status = Dropdown that is either 'Active' or 'In-Active' HHs_Allocated = Hidden | A number value that I need to update with HHs_Avaiable if 'Active". HHs_Avaiable = Hidden | A set number in the database. Any help would be greatly appreciated! <script type="text/javascript"> function myFunction() { var status = document.getElementsById("EditRecordStatus")[0].value; if (status == 'Active') {document.getElementById("EditRecordHHs_Allocated").value = document.getElementById("EditRecordHHs_Available").value;} else {document.getElementById("EditRecordHHs_Allocated").value = "0";} } document.getElementById("caspioform").onsubmit=myFunction; </script> Thanks! Compu Quote Link to comment Share on other sites More sharing options...
0 Jan Posted April 23, 2014 Report Share Posted April 23, 2014 Hello Compu, the line var status = document.getElementsById("EditRecordStatus")[0].value; contains "-s" - should be getElementById not ElementS. And the line returns the value of the first item in the dropdown, not the value of the selected item. You can use the following code instead of this line: var tempvar = document.getElementById("EditRecordStatus"); var status = tempvar.options[tempvar.selectedIndex].value; I hope it helps. Quote Link to comment Share on other sites More sharing options...
0 Compu Posted April 23, 2014 Author Report Share Posted April 23, 2014 Hey Jan, Thank you very much for your help. I used the following code but not getting anything: <script type="text/javascript"> function myFunction() { var tempvar = document.getElementById("EditRecordStatus"); var status = tempvar.options[tempvar.selectedIndex].value; if (status == 'Active') {document.getElementById("EditRecordHHs_Allocated").value = document.getElementById("EditRecordHHs_Available").value;} else {document.getElementById("EditRecordHHs_Allocated").value = "0";} } document.getElementById("caspioform").onsubmit=myFunction; </script> Quote Link to comment Share on other sites More sharing options...
0 Compu Posted April 23, 2014 Author Report Share Posted April 23, 2014 Update: I have been able to get the code to work in the preview window but it does not work once deployed. I am working on a page with multiple datapages, could that have something to do with it? Thanks! Quote Link to comment Share on other sites More sharing options...
0 Compu Posted April 24, 2014 Author Report Share Posted April 24, 2014 Just a heads up to anyone else that may run into this issue. You can use a div tag in the header with an ID, close the ID in the footer, and call the div tag in the function: document.getElementById('div_id').onsubmit=function() Found the answer here: http://forums.caspio.com/index.php/topic/3379-multiple-submission-form-in-a-single-web-page/?hl=%2Bmultiple+%2Bdatapage#entry10610%C2'> Thanks again Jan for the help! Quote Link to comment Share on other sites More sharing options...
Question
Compu
Trying to get a script to work on a single record update forum to update a field based on a dropdown value and can't figure out what I'm doing wrong.
Status = Dropdown that is either 'Active' or 'In-Active'
HHs_Allocated = Hidden | A number value that I need to update with HHs_Avaiable if 'Active".
HHs_Avaiable = Hidden | A set number in the database.
Any help would be greatly appreciated!
Thanks!
Compu
Link to comment
Share on other sites
4 answers to this question
Recommended Posts
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.