Results 1 to 8 of 8

Thread: Assign selected field value from combo to var and send to db table

  1. #1
    Join Date
    Mar 2003
    Location
    Chennai, India
    Posts
    25

    Assign selected field value from combo to var and send to db table

    Hi all,

    I extract the the commands stored in a certain directory to a combobox. The user selects the appropriate value in relation to some other field.Is there a way that the selected value be assigned to an initially blank value and sent to the database as a variable.

    I hope there should be a way for this to be achieved.

    Valid comments are welcome.

    Regards
    Karthikeyan

  2. #2
    Join Date
    Feb 2003
    Location
    Johannesburg, South Africa
    Posts
    145
    Depends on your programming environment. In Perl it's easy ( as in PHP, I understand ). In Perl, I may have a value in $value variable, and I simply pass this to MySQL:

    SELECT something FROM table WHERE this = '$value';

    Whatever's in $value, will be inserted in the actual MySQL statuement once it executes on the Server.

    Cheers

  3. #3
    Join Date
    Mar 2003
    Location
    Chennai, India
    Posts
    25

    Combobox value assignment to a variable...

    Hi Nico,

    That's not the problem. I have a combobox which displays the commands from a directory. I want the selected value to be assigned to a variable without even listing <option,value> pairs. By default, it will have Select a command. Is this possible, by any chance. If possible,tell me the way that can be achieved.

    Regards
    Karthikeyan

  4. #4
    Join Date
    Feb 2003
    Location
    Johannesburg, South Africa
    Posts
    145
    I hope I understand you correctly... Here goes.

    I assume you want to do the following:

    Code:
    <select name="commands">
      <option value="1">Command Name 1</option>
      <option value="2">Command Name 2</option>
      <option value="3">Command Name 3</option>
    </select>
    In Perl, your mapping will be something like (assuming your Form decoded values are in %FORM):

    Code:
         1	$definedcommands{ '1' } = "command 1 goes here...";
         2	$definedcommands{ '2' } = "command 2 goes here...";
         3	$definedcommands{ '3' } = "command 3 goes here...";
         4	
         5	if ( ( $FORM{ 'commands' } ) && ( $FORM{ 'commands' } =~ /^\d+$/ ) ) {
         6	
         7		$key = $FORM{ 'commands' };
         8		$command = $definedcommands{ $key };
         9		@lines = `$command`;
        10	
        11	} else {
        12	
        13		# error routine goes here...
        14	
        15	}
        16
    As you can see, the commands are predefined in a hash called %definedcommands and we simply match the returned value from the form as a key for this hash. The command can obviously be SQL commands as well.

    How you define your %definedcommands is up to you.

    Cheers

  5. #5
    Join Date
    Mar 2003
    Location
    Chennai, India
    Posts
    25
    Hi Nico,

    I am able to load the neccessay commands onto the combobox by a perlscript. What I am trying to do is HTML selection list option selection.

    i) Do we neccessarily give all the options with <option,pair> tags?
    ii) Does onChange() eventhandler be able to assign the changed value to default "" and able to port to the server when we submit
    Does this understandable now?

    Greetings
    Karthikeyan

  6. #6
    Join Date
    Feb 2003
    Location
    Johannesburg, South Africa
    Posts
    145
    This is unfortunately a HTML/JavaScript question then and not really MySQL related. I would suggest you Google a bit more for the answers. I have found the following pages interesting:

    * http://ruskfamily.com/htmlgd/tagoptio.html

    * http://www.devguru.com/Technologies/...ml_select.html

    Personally I steer clear of these complexities, as I want the web page as accesable as possible. In the end it's up to you.

    Cheers

  7. #7
    Join Date
    Mar 2003
    Location
    Chennai, India
    Posts
    25
    Hi Nico,

    Objective:
    ----------
    To list the commands from a directory. Assign to a var named script. Corresponding to this user supplies operation name in a form textbox. When form is submitted, the values of both operation and script should be displayed. when "CREATE THIS OPERATION" is clicked, the values are added to the database table named operation with the fields as
    operation and script.

    Currently, I acheive this without checking part. I seek your help since you know perl better than me.

    Situation:
    ----------
    I list the commands from a directory through perl script as follows

    Combobox listing:
    my $script = "<select name=script>\n";
    for my $h (@svalues) //sorted commands from dir.
    {
    $script .= "<option value=\"".$h."\">".$h."\n";
    }
    $script .= "</select>\n";

    I display in the web-page as,
    ------------------------------
    <td>$script</td>

    After this I need to show the prepared script to the user before sending it to the table(along with the operation corresponding to the command - which is also passed as form textbox value to a perl script.

    Kindly give me a clarification of how I can achieve the checking part.

    Regards
    Karthikeyan

  8. #8
    Join Date
    Mar 2003
    Location
    Chennai, India
    Posts
    25
    Got the solution a week back but unable to post immediately.

    I will give a hint only here. If elaborate code is needed, you can mail to my mailid.

    i) Assign a variable,say $scr with "<select name=blah>\n"; and concatenate with <option value=\"".$var."\">\n; and finish the </select>

    ii) In the HTML sheet, within table definition
    <td>$scr</td> will display the combobox list.

    iii) The selected value is referred by $query->param instance.

    iv) Then prepare as a hidden type data to add it to the database.

    Cheers
    Karthikeyan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •