Jump to content
  • 0

Can't Make Dropdown Changes Work In Insertrecord Form


financemy

Question

Hi all,

 

I've got a very frustrating problem that I can't seem to solve, and it's driving me nuts.

 

Form is http://www.createafoundation.org/enquire

 

In my insert record form, I have a field called "caf_code" that is hidden dropdown list populated from a view (hidden by a rule on the datapage).  I pass a variable to the form (via a cookie and some js) that sets the index of the dropdown list depending on the variable value.  This works fine, and I can query the javascript console to confirm that the dropdown has the right index and value even though it is hidden.

 

Now, when I submit the form, the value doesn't carry through to the table ... there is a blank field instead of the dropdown value.

 

If I now unhide the dropdown (using another control and another rule on the datapage) and submit the form, the value gets updated with the dropdown value correctly.

 

I tested both hidden and unhidden with the javascript console, and each time they report the same index and value... but only the "unhidden" scenario ends up with data in the right field.

 

This is really frustrating and I'm not sure where to go to from here.  Everything else seems to work OK...

 

Javascript code attached:

<script type="text/javascript">
 //this is the dropdown, hidden by a datapage rule
 var c = document.getElementById("InsertRecordcaf_code");
 //currently selected index
 var sel = c.selectedIndex;
 //number of entries
 var all = c.options.length;
 var i=0;
// get the variable in the cookie 
var cookie_caf = readCookie("CAF_code");
 //if there is no cookie, set to a default value
 if (cookie_caf == "") {
	cookie_caf = "3MAC";
 }
 
 //now iterate through dropdown and find matching entry
 var list_caf = c.options[sel].text;
 if (cookie_caf != list_caf) {
  for (i = 0; i < all; i++) {  
	  if (c.options[i].text == cookie_caf) {
                //found it - make it the selected entry
		c.options[i].selected = true;
	   break;
	  }
     }
 }
 else {
 	//is first entry on the list
 	c.options[0].selected = true;
 }

//set up partner email value 
document.getElementById("InsertRecordpartner_email").value = cookie_caf+ "@createafoundation.org";
//extract partner code for email 
document.getElementById("cbParamVirtual1").value = c.options[i].text;

//set up functions for changing of dropdowns
document.getElementById("InsertRecordcaf_code").onchange = caf_changed;
document.getElementById("cbParamVirtual2").onchange = got_caf_changed;

//dropdown for partner code
function caf_changed() {
	// caf code has changed - update other fields
	document.getElementById("InsertRecordpartner_email").value = document.getElementById("InsertRecordcaf_code").options[document.getElementById("InsertRecordcaf_code").selectedIndex].value+"@createafoundation.org";
	document.getElementById("cbParamVirtual1").value = document.getElementById("InsertRecordcaf_code").options[document.getElementById("InsertRecordcaf_code").selectedIndex].value;
}

//dropdown for 'do you have a partner code'
function got_caf_changed() {
	if (document.getElementById("cbParamVirtual2").value == "No") {
		//set default email
                document.getElementById("InsertRecordpartner_email").value = "3MAC@createafoundation.org";
                //find default in the dropdown and select
  		for (i = 0; i < all; i++) {  
      		if (document.getElementById("InsertRecordcaf_code").options[i].text == "3MAC") {
       			document.getElementById("InsertRecordcaf_code").options[i].selected = true;
       			document.getElementById("cbParamVirtual1").value = document.getElementById("InsertRecordcaf_code").options[i].text;
       			break;
      		}
            }
	}
}

</script>
Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Found out that this is "by design"

 

When a control is hidden by a rule, the value is not saved in the table on InsertRecord.  Unhiding the control means that the value is saved

 

When a control is hidden by javascript, or via marking it "hidden" in the control type, the value is saved in the table on InsertRecord

 

Hopefully this helps others

Mark

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