Solved

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

Posted on 2010-09-24
20
451 Views
Last Modified: 2012-05-10
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)';

            
0
Comment
Question by:sydneyguy
  • 13
  • 4
  • 3
20 Comments
 
LVL 63

Expert Comment

by:Zvonko
ID: 33755313
You need something to alert().

Like this:

onchange="  alert(42);"

 

0
 

Author Comment

by:sydneyguy
ID: 33755578
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>';

}
0
 

Author Comment

by:sydneyguy
ID: 33755716
$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
0
 
LVL 6

Accepted Solution

by:
neorush earned 250 total points
ID: 33755900
You had several syntax problems, this should work:
$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);">';

To see the values for testing you could use 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;alert(v.substr(1));">';
0
 

Author Comment

by:sydneyguy
ID: 33755918
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
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 33756077
Look in the browser resulting html text and you will see whether you get single " instead of "" and so on.

0
 
LVL 6

Expert Comment

by:neorush
ID: 33756092
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="" />
0
 

Author Comment

by:sydneyguy
ID: 33756480
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
0
 

Author Comment

by:sydneyguy
ID: 33756537
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
0
 

Author Comment

by:sydneyguy
ID: 33756610
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
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 6

Expert Comment

by:neorush
ID: 33756649
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

0
 
LVL 63

Expert Comment

by:Zvonko
ID: 33756677
The text is not HTML.
Can you perhaps save the complate HTML page from browser and apload the text file to EE?
0
 

Author Comment

by:sydneyguy
ID: 33759671
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
0
 
LVL 63

Assisted Solution

by:Zvonko
Zvonko earned 250 total points
ID: 33759884
You can alwasy do this:
<some html tags for your select and other html tags>
  <more tags>
</last tag of objects that you want to acces in your script>
<script>
function thatAccessUpperTags(){
  alert(42);
}
 thatAccessUpperTags();
</script>

That mean that you do not need to use onLoad event handler to test some script.
You can place anywhere on the page but always below the last tag that you want to use in your script.
For example placing additional script with function definitions andfunction calls is best done at the bottom of the html page because all tags are loaded at that page location.

And please post your HTML page source for more help.


0
 

Author Comment

by:sydneyguy
ID: 33762370
$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
0
 

Author Comment

by:sydneyguy
ID: 33762378
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
0
 

Author Comment

by:sydneyguy
ID: 33765057
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
0
 

Author Comment

by:sydneyguy
ID: 33791236
easy follow on question if your interesed still on the same issue just quick question about a line of code
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_26509070.html
0
 

Author Comment

by:sydneyguy
ID: 33794594
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
0
 

Author Closing Comment

by:sydneyguy
ID: 34133134
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
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
getting id from database 5 24
update field on focusout 15 23
Test ddwrt:UserLookup 1 22
contractual requirements for app hosting 3 26
New Relic: Our company recently started researching several products to figure out what were the best ways for us to increase our web page speed and to quickly identify performance problems that we may be having. One of the products we evaluated wa…
Developer tools in browsers have been around for a while, yet they are still heavily underused by developers. Developers still fix html or CSS then refresh page to see effect, or they put alert or debugger in JavaScript and then try again and again …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now