1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

MySQL query from form's output - Help !

Discussion in 'Web Design, HTML And CSS' started by coool, Jul 12, 2007.

  1. coool

    coool New Member

    Joined:
    Jul 12, 2007
    Messages:
    46
    Likes Received:
    0
    Trophy Points:
    0
    Hey guys,

    I need to wright a MySQL query that take the items of selectedFields to be as my fields in the output table

    I mean something like that: SELECT (all items of selectedField list) FROM table1

    what should be instead of (all items of the selectedField list) .. !!??

    Code:
    <HTML>
    <HEAD>
    <TITLE>Form</TITLE>
    <SCRIPT LANGUAGE="JavaScript" SRC="form.js"></SCRIPT>
    </HEAD>
    <BODY>
         <style type="text/css">
           #list { width: 200px;}
           #button {width: 100px;}
         </style>
          <br/>
          <h1>Field Selection</h1>
          <form name="fieldselectionform">
            <table width="100%">
              <tr>
                <td nowrap>Available Fields</td>
                <td>&nbsp;</td>
                <td nowrap>Selected Fields</td>
                <td>&nbsp;</td>
                <td rowspan=2 align="center" valign="bottom">
                  <input type="button" id="button" value="Clear Form" onClick="moveAllOptions(document.forms[0]
    
    ['selectedFields'],document.forms[0]['availableFields']); ">
                </td>
              </tr>
              <tr>
                <td width="20%">
                  <select size="20" id="list" multiple name="availableFields" onDblClick="moveSelectedOptions(this.form
    
    ['availableFields'],this.form['selectedFields'])">
    <option value=\"item_1">Item 1</option>
    <option value=\"item_2">Item 2</option>
    <option value=\"item_3">Item 3</option>
    <option value=\"item_4">Item 4</option></select>
                </td>
                <td width="20%" align="center" valign="center" nowrap>
                <input type="button" id="button" name="add" value=">>" onClick="moveSelectedOptions(document.forms[0]
    
    ['availableFields'],document.forms[0]['selectedFields']);">
                  <br><br>
                  <input type="button" id="button" name="remove" value="<<" onClick="moveSelectedOptions(document.forms
    
    [0]['selectedFields'],document.forms[0]['availableFields']);">
                </td>
                <td width="20%">
                  <select size="20" multiple id="list" name="selectedFields" onDblClick="moveSelectedOptions(this.form
    
    ['selectedFields'],this.form['availableFields'])">
                  </select>
                </td>
                <td width="20%" align="center" valign="center" nowrap>
    	<INPUT TYPE="button" id="button" VALUE="Move Up" onClick="moveOptionUp(this.form
    
    ['selectedFields'])">
    	<BR><BR>
    	<INPUT TYPE="button" id="button" VALUE="Move Down" onClick="moveOptionDown(this.form
    
    ['selectedFields'])">
                </td>
              </tr>
            </table>
          </form>
    </BODY>
    </HTML>
    
    here's java functions:
    Code:
    // -------------------------------------------------------------------
    // moveSelectedOptions(select_object_From,select_object_To)
    //  This function moves options between select boxes. Works best with
    //  multi-select boxes to create the common Windows control effect.
    //  Passes all selected values from the first object to the second
    //  object.
    //  You can also put this into the <SELECT> object as follows:
    //    onDblClick="moveSelectedOptions(this,this.form.target)
    //  This way, when the user double-clicks on a value in one box, it
    //  will be transferred to the other (in browsers that support the 
    //  onDblClick() event handler).
    // -------------------------------------------------------------------
    function moveSelectedOptions(from,to) {
    	// Move them over
    	if (!hasOptions(from)) { return; }
    	for (var i=0; i<from.options.length; i++) {
    		var o = from.options[i];
    		if (o.selected) {
    			if (!hasOptions(to)) { var index = 0; } else { var index=to.options.length; }
    			to.options[index] = new Option( o.text, o.value, false, false);
    			}
    		}
    	// Delete them from original
    	for (var i=(from.options.length-1); i>=0; i--) {
    		var o = from.options[i];
    		if (o.selected) {
    			from.options[i] = null;
    			}
    		}
    	from.selectedIndex = -1;
    	to.selectedIndex = -1;
    	}
    
    // -------------------------------------------------------------------
    // moveOptionUp(select_object)
    //  Move selected option in a select list up one
    // -------------------------------------------------------------------
    function moveOptionUp(obj) {
    	if (!hasOptions(obj)) { return; }
    	for (i=0; i<obj.options.length; i++) {
    		if (obj.options[i].selected) {
    			if (i != 0 && !obj.options[i-1].selected) {
    				swapOptions(obj,i,i-1);
    				obj.options[i-1].selected = true;
    				}
    			}
    		}
    	}
    
    // -------------------------------------------------------------------
    // moveOptionDown(select_object)
    //  Move selected option in a select list down one
    // -------------------------------------------------------------------
    function moveOptionDown(obj) {
    	if (!hasOptions(obj)) { return; }
    	for (i=obj.options.length-1; i>=0; i--) {
    		if (obj.options[i].selected) {
    			if (i != (obj.options.length-1) && ! obj.options[i+1].selected) {
    				swapOptions(obj,i,i+1);
    				obj.options[i+1].selected = true;
    				}
    			}
    		}
    	}
    
    // -------------------------------------------------------------------
    // selectAllOptions(select_object)
    //  This function takes a select box and selects all options (in a 
    //  multiple select object). This is used when passing values between
    //  two select boxes. Select all options in the right box before 
    //  submitting the form so the values will be sent to the server.
    // -------------------------------------------------------------------
    function selectAllOptions(obj) {
    	if (!hasOptions(obj)) { return; }
    	for (var i=0; i<obj.options.length; i++) {
    		obj.options[i].selected = true;
    		}
    	}
    
    // -------------------------------------------------------------------
    // moveAllOptions(select_object,select_object[,autosort(true/false)[,regex]])
    //  Move all options from one select box to another.
    // -------------------------------------------------------------------
    function moveAllOptions(from,to) 
    {
    	selectAllOptions(from);
    	moveSelectedOptions(from,to);
    }
    
    
    // -------------------------------------------------------------------
    // hasOptions(obj)
    //  Utility function to determine if a select object has an options array
    // -------------------------------------------------------------------
    function hasOptions(obj) {
    	if (obj!=null && obj.options!=null) { return true; }
    	return false;
    	}
    
    // -------------------------------------------------------------------
    // swapOptions(select_object,option1,option2)
    //  Swap positions of two options in a select list
    // -------------------------------------------------------------------
    function swapOptions(obj,i,j) {
    	var o = obj.options;
    	var i_selected = o[i].selected;
    	var j_selected = o[j].selected;
    	var temp = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
    	var temp2= new Option(o[j].text, o[j].value, o[j].defaultSelected, o[j].selected);
    	o[i] = temp2;
    	o[j] = temp;
    	o[i].selected = j_selected;
    	o[j].selected = i_selected;
    	}
    
     

Share This Page