Jump to content
  • 0

Update Field Based On Dropdown


Compu

Question

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

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

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.

Link to comment
Share on other sites

  • 0

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>
Link to comment
Share on other sites

  • 0

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!

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
Answer this question...

×   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...