Link to home
Start Free TrialLog in
Avatar of sydneyguy
sydneyguyFlag for Australia

asked on

php java cascade and multiselect box need to be able to extract the multi select ans still cascade

i have a section of code that i am assembaling from a cascade menu as below. can get the alert pop up to work, and can get the values of the select box with the below code. but when the system builds its self it creates the code by addign the line of code but cannot get the syntax correct to  work ...any help woudl be appreciated

********  this is the code runs and when select is clicked an alert box comes up ********
code 1 working
if ($config['accept_county'] == 'Y' || $config['accept_county'] == '1') {       
            /* MODIFIED FOR MULTI SELECT  */
          $ret .= '     <select size="10" multiple="multiple" style="width: 175px " 
onchange="  alert()"; >';
***** the below code needs to be substituted were onchange="  alert()";  lives to allow me to on
code 2 need to be substituted
click cycle through the items selected and save it to a text box *************

onChange='var v="",o=this.options;
      for(var i=0;i<o.length;i++)
      if(o[ i ].selected)v+=","+o[ i ] .value;
      this.form.GenDisClassComb.value=v.substr(1)';

            
Avatar of Zvonko
Zvonko
Flag of North Macedonia image

You need something to alert().

Like this:

onchange="  alert(42);"

 

Avatar of sydneyguy

ASKER

sorry that works if you run it a blank alert box comes up that actually works of
what i need to do change

onchange="  alert()"; >';
to   the code below, but get the syntax correct which i just cannot seem to get
onChange='var v="",o=this.options;
      for(var i=0;i<o.length;i++)
      if(o[ i ].selected)v+=","+o[ i ] .value;
      this.form.GenDisClassComb.value=v.substr(1)';

its used in the context as below building the $ret .= '

function DiseasesModeledBuild($countrycode) {
      global $config;
      if ( ($config['accept_country'] == '1' || $config['accept_country'] == 'Y' )  && $countrycode == 'AA' )  {
            return '<input name="srchlookstate_provincedis" type="text" class="textinput" size="30" maxlength="100" />';
      }
      $ret = '';
      $data = DiseasesModeled(trim($countrycode),'N');
      if (count($data) < 1) return '<input name="srchlookstate_provincedis" type="text" class="textinput" size="30" maxlength="100" />';
      if ($config['accept_county'] == 'Y' || $config['accept_county'] == '1') {       
            /* MODIFIED FOR MULTI SELECT   **********  PROBLEM BELOW */
            $ret .= '      <select size="10" multiple="multiple" style="width: 175px"
                        onchange="  alert()"; >';  /* THIS NEEDS TO CHANGE */
            
            /* onchange="javascript: cascadeState(this.value,this.form.srchlookcountry.value);" */
      }
      /* $ret .= '<option value="AA">'.get_lang('select_organtissue').'</option>'; */

      foreach ($data as $k => $y){
            if ($k != 'AA') {
                  $ret .= "<option value='$k'>$y</option>";
            }
      }
      unset ($data);

      return $ret .= '</select>';

}
$ret .= '      <select size="10" multiple="multiple" style="width: 175px"
                        onChange="var v="",o=this.options;
                            for(var i=0;i<o.length;i++)
                            if(o[i].selected)v+=","+o[i].value;
                            this.form.GenDisClassComb.value=v.substr(1)"; >';

THIS IS THE CORRECT SYNTAX WHICH WILL COMPILE AND RUN BUT WILL NOT RUN THE ONCHANGE FUNCTION
ASKER CERTIFIED SOLUTION
Avatar of neorush
neorush

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
this code is created dynamicaly as the cascade parent is selected the cascade code jumps to and finds all the options required from the parent , then this code should be set up on the select box to allow the onchange code to run.
i can get the alert () code to run but will not run the item select code???
must be a syntex or txt box not found in form or some thing silly
Look in the browser resulting html text and you will see whether you get single " instead of "" and so on.

Avatar of neorush
neorush

it is trying to update a form element with name "GenDisClassComb" Most of the time this is something like a hidden field.  You could try using document.getElementById() and make sure the field you are trying to update has a unique id so the code would change to this:
$ret .= '<select size="10" multiple="multiple" style="width: 175px"
                        onChange="var v=\'\';o=this.options; for(var i=0;i<o.length;i++) if(o[i].selected)v+=\',\'+o[i].value;document.getElementById(\'GenDisClassComb\').value=v.substr(1);">';

and the hidden field might be something like this:
<input type="hidden" name="GenDisClassComb" id="GenDisClassComb" value="" />
Zvonko: the page is cnstructed dynamicaly so if you do a page source it shows the original line code
but did a varable drop out and here is the code

*********************  does not work ***************** see below for alert that does work
\t<select size="10" multiple="multiple" style="width: 175px"\n\t\t\tonChange="var v="",o=this.options;\n\t\t                for(var i=0;i<o.length;i++)\n\t\t                if(o[i].selected)v+=","+o[i].value;\n\t\t                this.form.DiseasesModeledComb.value=v.substr(1);"\t\n\n\t\t\n\t\t\n\t\t\n\t\t\n\t\t><option value='anaemia'>anaemia</option><option value='aneurysm'>aneurysm</option><option value='angina'>angina</option><option value='arrhythmia'>arrhythmia</option><option value='arteriosclerosis'>arteriosclerosis</option><option value='cardiac arrest'>cardiac arrest</option><option value='cardiac tumour'>cardiac tumour</option><option value='cardiomyopathy'>cardiomyopathy</option><option value='congestive heart failure'>congestive heart failure</option><option value='Deep Vein thrombosis'>Deep Vein thrombosis</option><option value='DVT'>DVT</option><option value='embolism'>embolism</option><option value='heart valve disease'>heart valve disease</option><option value='hypertension'>hypertension</option><option value='hypotension'

************************ this works with the alert ****************************
\t<select size="10" multiple="multiple" style="width: 175px"\n\t\t\tonchange="  alert()";\t\n\n\t\t\n\t\t\n\t\t\n\t\t\n\t\t><option value='anaemia'>anaemia</option><option value='aneurysm'>aneurysm</option><option value='angina'>angina</option><option value='arrhythmia'>arrhythmia</option><option value='arteriosclerosis'>arteriosclerosis</option><option value='cardiac arrest'>cardiac arrest</option><option value='cardiac tumour'>cardiac tumour</option><option value='cardiomyopathy'>cardiomyopathy</option><option value='congestive heart failure'>congestive heart failure</option><option value='Deep Vein thrombosis'>Deep Vein thrombosis</option><option value='DVT'>DVT</option><option value='embolism'>embolism</option><option value='heart valve disease'>heart valve disease</option><option value='hypertension'>hypertension</option><option value='hypotension'>hypotension</option><option value='myocarditis'>myocarditis</option><option value='pernicious anaemia'>pernicious anaemia</option><option value='rheumatic heart disease'>rheumatic
neorush:
have placed the field
<input type="hidden" name="GenDisClassComb" id="GenDisClassComb" value="" />
is on the page and is between the page format
wil try on return to enter known data into the field to tet that way
it is trying to update a form element with name "GenDisClassComb" Most of the time this is something like a hidden field.  You could try using document.getElementById() and make sure the field you are trying to update has a unique id so the code would change to this:

have the text set up it runs and no errors but still does not update the text field
I noticed that the next example you gave used "DiseasesModeledComb" as the name of the field to update...if the field does not exist it can not be updated.  Here is a simple example of what has to be in place for this to work:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><head><title>TEST</title></head>
<body>
<form name="testForm">
<select size="10" multiple="multiple" style="width: 175px" onChange="var v='';o=this.options; for(var i=0;i<o.length;i++) if(o[i].selected)v+=','+o[i].value;this.form.DiseasesModeledComb.value=v.substr(1);">
	<option value="1">Option 1</option>
	<option value="2">Option 2</option>
	<option value="3">Option 3</option>
	<option value="4">Option 4</option>
	<option value="5">Option 5</option>
</select>
<input type="text" name="DiseasesModeledComb" value="NOT UPDATED YET" />
</form>
</body>
</html>

Open in new window

The text is not HTML.
Can you perhaps save the complate HTML page from browser and apload the text file to EE?
can you have 2 on load events cause what you said makes sense,
the test code in the html page still has the onchange, cascade event, were what is required is the cascade event as well as updatign the text box, i am now in the process of testing the txt box for data adding to make sure that that is right.
the page has in fo in it that my clients woudl not want out there but i will build a cut down replicia and place that up, and psuh the question along.
again can i have a statment
onchange pt 1
onchange pt 2
so 2 different functions for an on change event, then i could add the present data to the txt box.
i willalso try a littl bit of on screen java to add the code to the box to allow me to test the select box as well as the txt box and then go from there
thanks for all your help so far
garry
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
$ret .= '<select size="10" multiple="multiple" style="width: 175px" name="srchlookstate_provincedis"
               onchange=" alert(this.form.name=srchlookstate_provincedis.value);" >';

this wil now retreive the value of the box its self so the reload is working and i can see the box an display the values
YET THE BELOW CODE THAT EXTRACTS THE VALUE AND PACES IN ANOTHER TEXTBOX WILL NOT PHASE AND IS NOT SYNTAX CORRECT. HAVE PLACED IMAGE OF DEBUG CODE

$ret .= '<select size="10" multiple="multiple" style="width: 175px" name="srchlookstate_provincedis"
               onChange='var v="",o=this.options;
                            for(var i=0;i<o.length;i++)
                            if(o[i].selected)v+=","+o[i].value;
                            this.form.CellEffectsMonComb.value=v.substr(1)'; >


cascade-orror.png
have been trying to get a html page dump, but because the code does not run it cannot build its self with the code to look at
have included the html page drop out, but it does get a bit conveluted, as the system goes through several php files a few functions and a tpl page to return the data for page display as well as the error.
i have attaced a word doc,
the incorrect code is in BLUE this is the code that does not work.
the code in red is from another box doing the same thing and works the only difference is the the red box is not driven of the top item select, were the one in blue requires dynamic java to rebuild the options table and then place the info in the listbox above.
hope this make it a bit more clear. have spent days on this problem and think that i am close.
advsearch-html-output.doc
easy follow on question if your interesed still on the same issue just quick question about a line of code
https://www.experts-exchange.com/questions/26509070/'-srchlookstate-province-'-php-what-does-this-do.html
would it help if i put up a small site to show you what was happening coudl i get some one to have a look and see what i am missing is that possible
thanks for all the help. has taken me a long way down the track, and will have more indepth questions down the track
as i have now a better idea on what isrequired