Jump to content

Auto Submit Dropdown


Recommended Posts

8 minutes ago, techguy said:

As a note, I have responsive turned off since it buggers up the styling if it is on. I have it in a menu space and very specific css requirments. Not sure if the code changes with responsive is OFF

Ah I know it now. changing the values on JS will not trigger the eventlistener, you need to explicitly dispatch that event once the value changes.

Use this on both the if and else

document.getElementById('EditRecordStatusLocation').dispatchEvent(new Event('change'));

 


Here's my script

<script type="text/javascript">
document.getElementById("EditRecordyess").addEventListener('change', function(event) {
 
 if (document.getElementById("EditRecordyess").checked==true){
   document.getElementById("cbParamVirtual1").value='Online';
document.getElementById('cbParamVirtual1').dispatchEvent(new Event('change'));

 }

 else if (document.getElementById("EditRecordyess").checked==false){
   document.getElementById("cbParamVirtual1").value='Off';
document.getElementById('cbParamVirtual1').dispatchEvent(new Event('change'));
 }
 
});

</script>
<script type="text/javascript">
 
document.getElementById("cbParamVirtual1").addEventListener('change', function myFunction(event) {


// submit the form if an value is selected
setTimeout('document.forms["caspioform"].submit()',1000);  

});

</script>

 

This submits mine upon checking or unchecking

Link to comment
Share on other sites

Bravo!!! You are amazing!

 

a little more maybe....

1. Is there a way now in this script on the dropdown, when the selected option is 'Off' it also turns the checkbox off (unchecks it?)

2. does the page refresh on submit on refresh because it is a single record update page? Should I try to make this work with another page type. The refreshing of the entire page sucks, lol

 

 

Thank you soooooo much. a few little tweaks hopefully and one less task!!!

 

Link to comment
Share on other sites

21 minutes ago, techguy said:

Bravo!!! You are amazing!

 

a little more maybe....

1. Is there a way now in this script on the dropdown, when the selected option is 'Off' it also turns the checkbox off (unchecks it?)

2. does the page refresh on submit on refresh because it is a single record update page? Should I try to make this work with another page type. The refreshing of the entire page sucks, lol

 

 

Thank you soooooo much. a few little tweaks hopefully and one less task!!!

 

what field is that dropdown? Is it the status location or an entirely different one not used in the script?

 

2. No, it ALWAYS refreshed upon submission of form. It's an HTML thing. 

Link to comment
Share on other sites

14 minutes ago, techguy said:

The dropdown is the one called  StatusLocation - all on same script and datapage

 

on the refresh.. so if I update, then it will not refresh the whole page? If I submit form it does?

 

 

Here;s an updated code

Virtual 2 is my dropdown 


You can put the dispatch event after the if elses instead so you'll have shorter code

 

2nd script tag is what I added

<script type="text/javascript">
document.getElementById("EditRecordyess").addEventListener('change', function(event) {
 
 if (document.getElementById("EditRecordyess").checked==true){
   document.getElementById("cbParamVirtual2").value='Online';


 }

 else if (document.getElementById("EditRecordyess").checked==false){
   document.getElementById("cbParamVirtual2").value='Off';

 }
document.getElementById('cbParamVirtual2').dispatchEvent(new Event('change'));
});

</script>

<script type="text/javascript">
document.getElementById('cbParamVirtual2').addEventListener('change', function(event) {
 
 if (document.getElementById('cbParamVirtual2').value=='Online'){
  document.getElementById("EditRecordyess").checked=true;


 }

 else if (document.getElementById('cbParamVirtual2').value=='Off'){
  document.getElementById("EditRecordyess").checked=false;


 }

document.getElementById("EditRecordyess").dispatchEvent(new Event('change'));
});

</script>


<script type="text/javascript">
 
document.getElementById("cbParamVirtual2").addEventListener('change', function myFunction(event) {


// submit the form if an value is selected
setTimeout('document.forms["caspioform"].submit()',1000);  

});

</script>





 

No Update and Submit works as "Submit Form"

tabular reports is MUCH harder to do custom coding on

Link to comment
Share on other sites

  • 2 months later...

I am using a tabular report where the search form is above the results table, not on a separate page. The script above works, as it is submitting the search button when any dropdown value is selected. 

However, upon loading the new results, the search form is no longer on top of the results. It is missing, with no way to get back to it unless I reload the page.

Anyone have any ideas on how to fix this? I'd like to always keep the search form above the results page.

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