#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    5
    Rep Power
    0

    Multiple selection form without CTRL problem


    Hi.

    Hope you can help me with a small problem. It is a "malfunction" in the (I think) Javascript.

    First of the codes before I describe the event:

    The JS:
    Code:
    echo "<script type=\"text/javascript\">
    	var arrSel = new Array();
    	function AuswahlReset(objSel){
    	arrSel[String(objSel.selectedIndex)] = (arrSel[String(objSel.selectedIndex)])? false : true;
     
    	for(var i=0; i<objSel.options.length; i++){
        objSel.options[i].selected = (arrSel[String(i)])? true : false;
    	}
    	}
     
    	window.onload = function(){
    	AuswahlReset(document.f1.elements['vermitteltorg[]']);
    	}
    	</script>\n";
    The Box:
    PHP Code:
    $voarr explode(","$zeile['vermittorg']);
            echo 
    "<select size='10' multiple onchange='AuswahlReset(this)' name='vermitteltorg[]'>\n";
            echo 
    "<option value=\"0\">Keine gelistete Organisation</option>\n";
            
    $orgquery "SELECT * FROM freiwilligev2organisation ORDER BY einrichtung;";
     
            
    $orgresult $mysqli->query($orgquery);
     
            while (
    $orgzeile $orgresult->fetch_array()) {
                    
    $found 0;
                    foreach (
    $voarr as $key){
                            if (
    $orgzeile['id'] == $key) {
                                    
    $found 1;
                                    break;
                            }
                    }
     
                    if (
    $found)
                            echo 
    "<option value=\"" $orgzeile['id']. "\" selected>" $orgzeile['einrichtung'] . "</option>\n";
                    else
                            echo 
    "<option value=\"" $orgzeile['id']. "\">" $orgzeile['einrichtung'] . "</option>\n";
     
            }
            echo 
    "</select><br>\n"
    The problem:
    So the JS makes that you can select in the combo box without the CTRL key to keep it. This is to prevent accidental deselection during subsequent editing. The entry is saved with a form into a MySQL database. This all works wonderfully, but when said editing only the first of the last highlighted options appears. Example: It is 4 5 7, and after saving and re-call for editing is only the 4 pre-marked. But it is stored in the database, all 3 options. If I disable the JS is displayed when you call to edit all the options previously selected, so that seems to lie at the JS. Only I know exactly what ned to, because I really have no clue of JS.

    Anyone have an idea?

    Thank you and kind regards
    Doti
  2. #2
  3. No Profile Picture
    Super Moderator
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,008
    Rep Power
    2791
    Welcome to DevShed, dotwin.

    Post the X/HTML not the PHP, please. I can see a few issues with your Javascript but I would like to see the X/HTML before making a concise reply.
    [PHP] | [Perl] | [Python] | [Java] != [JavaScript] | [XML] | [ANSI C] | [C++] | [LUA] | [MySQL] | [FirebirdSQL] | [PostgreSQL] | [HTML] | [XHTML] | [CSS]

    W3Fools - A W3Schools Intervention.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    5
    Rep Power
    0
    Here is the complete HTML code. Unfortunately, I can only link to the txt file, everything beyond the maximum scale of the Forum together about 71k sign

    The HTML Code:
    http:// www . file-upload . net / download-7476677 / html . txt . html

    And here the complete php file:
    http:// www . file-upload . net / download-7476671 / php . txt . html
  6. #4
  7. No Profile Picture
    Super Moderator
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,008
    Rep Power
    2791
    What is the purpose of this?

    onload and onselect events trigger the script, which adds the selected option to the array, if it is not already in the array. It then loops through all of the options in your select comparing each option to each paired array value. If there is a match, the paired is selected in turn.

    This script is not logical, explain what you need it to do.
    [PHP] | [Perl] | [Python] | [Java] != [JavaScript] | [XML] | [ANSI C] | [C++] | [LUA] | [MySQL] | [FirebirdSQL] | [PostgreSQL] | [HTML] | [XHTML] | [CSS]

    W3Fools - A W3Schools Intervention.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    5
    Rep Power
    0
    I'll try again with my bad English to explain.
    So in these scripts already 3 people have worked, so it looks like cabbage and turnips.

    The JS will make it possible that in the selection without the Optinen the Ctrl key can be selected, it should be able to deselect the options have already been taken with just a click, and when you call the function edit the previously selected options reload so that other options may be removed or added.

    Hope you understand what I mean. as I said my English is not really good so help me with longer texts always google
  10. #6
  11. No Profile Picture
    Super Moderator
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,008
    Rep Power
    2791
    Ok, so your problem is that you cannot deselect an option once it has been selected?
    [PHP] | [Perl] | [Python] | [Java] != [JavaScript] | [XML] | [ANSI C] | [C++] | [LUA] | [MySQL] | [FirebirdSQL] | [PostgreSQL] | [HTML] | [XHTML] | [CSS]

    W3Fools - A W3Schools Intervention.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    5
    Rep Power
    0
    No, the problem is that the saved are not pre-labeled when the JS is active. So when I select option 2 3 4 5 then storable these options are saved properly in the database, but when calling the page to edit only the first of the 4 options is active, ie, in the example, the option 2 the 3 4 5 is indeed stored in the database, but not in form. if the js is not running and I have everything with ctrl mark and store all active when re-editing. only the two together does not get out. So script and proper pre-selection.
  14. #8
  15. No Profile Picture
    Super Moderator
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,008
    Rep Power
    2791
    I see. That is an issue with your PHP then, you will need to echo a variable or loop in your PHP directly into the Javascript array. Something like the following.
    PHP Code:
    $Js_array = '';
     
    $voarr = explode(",", $zeile['vermittorg']);
    		echo "<select size='10' multiple onchange='AuswahlReset(this)' name='vermitteltorg[]'>\n";
            echo "<option value=\"0\">Keine gelistete Organisation</option>\n";
            $orgquery = "SELECT * FROM freiwilligev2organisation ORDER BY einrichtung;";
     
            $orgresult = $mysqli->query($orgquery);
     
            while ($orgzeile = $orgresult->fetch_array()) {
                    $found = 0;
                    foreach ($voarr as $key){
                            if ($orgzeile['id'] == $key) {
                                    $found = 1;
                                    break;
                            }
                    }
     
                    if ($found) {
                            echo "<option value=\"" . $orgzeile['id']. "\" selected>" . $orgzeile['einrichtung'] . "</option>\n";
    						$Js_array .= $orgzeile['id'].',';
    				}
                    else
                            echo "<option value=\"" . $orgzeile['id']. "\">" . $orgzeile['einrichtung'] . "</option>\n";
     
            }
     
    $Js_array = rtrim($Js_array, ',');
     
    echo "</select><br>\n";
    Obviously that is not a complete answer as it does not fit in with your layout, you would need to perform your PHP functions seperately from your content dumps.

    Would you like me to move this to the PHP forum?
    [PHP] | [Perl] | [Python] | [Java] != [JavaScript] | [XML] | [ANSI C] | [C++] | [LUA] | [MySQL] | [FirebirdSQL] | [PostgreSQL] | [HTML] | [XHTML] | [CSS]

    W3Fools - A W3Schools Intervention.
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    5
    Rep Power
    0
    OK, so far I was just looking for problems with the JS, but if that is okay, then I'm already happy.
    I'm currently still in the pure PHP code because it was written by my predecessor and I look through not quite.

    Would be nice if you could move the thread in the PHP area, because I can be sure helped still good.

    Am very pleased that there is so helpful people. In the German forums where I have identified the problem, it was either ignore or as I called full post.

    As far as ever thank you.
    Last edited by Dotwin; April 16th, 2013 at 11:12 AM. Reason: Writing error :)

IMN logo majestic logo threadwatch logo seochat tools logo