By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,403 Members | 1,035 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,403 IT Pros & Developers. It's quick & easy.

2 Drop downs - setting selected value in 2nd using JS after iframe load

P: 2
I have the basic structure as follows:

2 drop downs A & B.

A is populated using (datasource methods - from database).
B is poulated using A's selected value as input and retrieve the list into B.
for this I use iframe & dynamic population.

so far so good.
now there is a 3rd variable based on which I need to make the B's drop down selected.

this is not working for me.

drop down list gets populated but it's not setting the value based on 3rd variable.

can anybody guide me how to resolve.
Sep 4 '07 #1
Share this Question
Share on Google+
2 Replies


gits
Expert Mod 5K+
P: 5,390
hi ...

welcome to TSDN ...

could you please post an example for your problem ... especially regarding to the point that is not working?

kind regards
Sep 4 '07 #2

P: 2
Ok, here;s the step by step for my issue:

1. there are 2 drop downs (both are populated using iframes) & datasource.

2. 1st drop down is populated when page loads. Second drop down depends on first drop down's select value.

3. Tricky part here is, user selects first drop down by another method not just selecting from drop down. He selects those values from another button,that's when I call selectRowDataForEdit method.. 2nd drop down populates after this method call.

all population occurs correctly but the 2nd drop down selected value is not set.

I think it's something to do with, iframe load occurs after javascript function is completed. hence it's not able to select the value when none is available.


It's little complicated. I guess an expert might see the issue immediately.

Expand|Select|Wrap|Line Numbers
  1. function parentUpdated(targetFieldName, parentFieldNames, parentParameterNames, dataSource) {
  2.     var url = "<c:url value="/dataset.do"/>?";
  3.     url += "dataSource=" + dataSource;
  4.     for (var i=0; i<parentFieldNames.length; i++) {
  5.         var field = document.getElementsByName(parentFieldNames[i]);
  6.         field = field[0];
  7.         if(field.value.length == 0) {
  8.          return;
  9.         }
  10.         url += "&" + escape(parentParameterNames[i]) + "=" + escape(field.value);
  11.     }    
  12.     updateSelectBox(url, targetFieldName);
  13.  }    
  14.  
  15.  
  16.  function selectRowDataForEdit(index,type){
  17. // alert("rowId ="+index);
  18.  
  19.  if(type == 'Payments'){
  20.  
  21.      document.forms['paymentInformationForm'].elements['obligorNumberSelected'].value = document.forms['paymentInformationForm'].elements['payments['+index+'].obligorNumber'].value;
  22.  
  23.      //alert("Selected value ="+document.forms['paymentInformationForm'].elements['obligorNumberSelected'].value);
  24.      parentUpdated("paymentInformation.obligationNumber", new Array("wdcuPackageId","obligorNumberSelected"), new Array("currentWDCUPackageID","selectedObligorNumber"), "com.comerica.wdcu.service.ObligationsDataSource");
  25.  
  26.      alert("obligation no: "+document.forms['paymentInformationForm'].elements['obligationNumberSelected'].value);
  27.  }
  28.     if(document.forms['paymentInformationForm'].elements['obligationNumberSelected'].value != ''){
  29.         var theDayElement = document.forms['paymentInformationForm'].elements['paymentInformationForGuarantee.obligationNumber']; 
  30.         var optionCounter;
  31.         for (optionCounter = 0; optionCounter < theDayElement.length; optionCounter++) {
  32.            alert("Option text is " + theDayElement.options[optionCounter].text) 
  33.            alert(" and its value is "+theDayElement.options[optionCounter].value);
  34.            if(document.forms['paymentInformationForm'].elements['obligationNumberSelected'].value == theDayElement.options[optionCounter].value){
  35.                alert("Inside...");
  36.                theDayElement.options[optionCounter].selected = true;
  37.            }
  38.         }
  39.         document.forms['paymentInformationForm'].elements['paymentInformation.obligationNumber'].value = document.forms['paymentInformationForm'].elements['obligationNumberSelected'].value;     
  40.         alert("This time ="+document.forms['paymentInformationForm'].elements['paymentInformation.obligationNumber'].value);
  41.     }
  42. }
  43.  
Sep 6 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.