Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #8508 > unrolled thread

Jquery to create 2 or multiple events in .change

Started by"Jesolo Sun" <gala@tiscali.it>
First post2011-11-21 11:21 +0100
Last post2011-11-23 18:16 -0800
Articles 6 — 4 participants

Back to article view | Back to comp.lang.javascript


Contents

  Jquery to create 2 or multiple events in .change  "Jesolo Sun" <gala@tiscali.it> - 2011-11-21 11:21 +0100
    Re: Jquery to create 2 or multiple events in .change Scott Sauyet <scott.sauyet@gmail.com> - 2011-11-21 05:31 -0800
      Re: Jquery to create 2 or multiple events in .change Gregor Kofler <usenet@gregorkofler.com> - 2011-11-21 23:32 +0100
        Re: Jquery to create 2 or multiple events in .change Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-22 01:12 +0100
          Re: Jquery to create 2 or multiple events in .change Scott Sauyet <scott.sauyet@gmail.com> - 2011-11-22 06:54 -0800
        Re: Jquery to create 2 or multiple events in .change Scott Sauyet <scott.sauyet@gmail.com> - 2011-11-23 18:16 -0800

#8508 — Jquery to create 2 or multiple events in .change

From"Jesolo Sun" <gala@tiscali.it>
Date2011-11-21 11:21 +0100
SubjectJquery to create 2 or multiple events in .change
Message-ID<4eca261b$0$1382$4fafbaef@reader2.news.tin.it>

I have first selectbox
<select id="stampa" name="stampa" onChange="calculateTotal();">
<option>Scegli...</option>
</select>

with Jquery i have 1 event with  .change
$(document).ready(function(){
    $("select#stampa").change(function(){
    var stampa = $("select#stampa option:selected").attr('value');

    $.post("select.php", {PrinttypeID:stampa}, function(data){
        $("select#colori").removeAttr("disabled");
        $("select#colori").html(data);
     });
});

after with select.php built the query

$opt = new SelectList();

if(isset($_POST['PrinttypeID']))
{
    echo $opt->ShowColori();
    die;
}
this query populate the <option... in the  selectbox  id="colori"


<select id="colori" name="colori" onChange="calculateTotal();">
<option>Scegli...</option>
</select>

public function ShowColori()
{
    include("sqlprotect.php");
    $sql_colori = new sqlprotect();
    $sql->secureGlobals();

    $sql_colori = "SELECT printtype.PrinttypeID, printtype.Printtype,
printtype_colors.PrinttypeColors as colors,
printtype_colors.PrinttypeColorsID as ID
            FROM printtype
            LEFT JOIN printtype_colors ON printtype_colors.PrinttypeID =
printtype.PrinttypeID
            WHERE printtype_colors.PrinttypeID=".$_POST[PrinttypeID]."
            ORDER BY printtype_colors.PrinttypeColors
            ";
    $res_colori = mysql_query($sql_colori,$this->conn);
    $colori = '<option value="0">scegli...</option>';

        while($row_colori = mysql_fetch_array($res_colori))
        {
            $colori .= '<option value="' . $row_colori['ID'] . '">' .
utf8_encode($row_colori['colors']) . '</option>\n';

        }


    return $colori;
}

I need to create an second event in $("select#stampa").change(function()

$(document).ready(function(){
    $("select#stampa").change(function(){
    var stampa = $("select#stampa option:selected").attr('value');

    $.post("select.php", {PrinttypeID:stampa}, function(data){
        $("select#colori").removeAttr("disabled");
        $("select#colori").html(data);
     });
});

I need to build another query.
If i create in this get me the error in the creation of the <option> value
if(isset($_POST['PrinttypeID']))
{
    echo $opt->ShowColori();
     echo $opt->ShowCosti();
    die;
}

The second event at the  .change is this:

if(isset($_POST['Quantity']))
{
    echo $opt->ShowCosti($_POST['Printtype'],$_POST['Quantity'] );

    die;
}

public function ShowCosti($PrinttypeID, $Quantita)
{
    include("sqlprotect.php");
    $sql_range_prezzo = new sqlprotect();
    $sql->secureGlobals();

    $sql_range_prezzo = " SELECT range_prezzo, range_aggiuntivo
                    FROM rangeprice
                    WHERE PrinttypeID = ".$PrinttypeID."
                    AND ".$Quantita."  between scaglione_range_da AND
scaglione_range_a
            ";
    $res_range_prezzo = mysql_query($sql_range_prezzo,$this->conn) or die
("Query Failed ".mysql_error(). print $sql_range_prezzo);

        while($row_range_prezzo = mysql_fetch_array($res_range_prezzo))
        {
            $range_prezzo = '<input name="costi"  id="costi" type=" text"
value="' . $row_range_prezzo['range_prezzo'] . '"
onchange="calculateTotal();"><br />';
            $range_prezzo .= '<input name="costi_agg"  id="costi_agg"
type="text" value="' . $row_range_prezzo['range_aggiuntivo'] . '"
onchange="calculateTotal();"><br />';
        }


    return $range_prezzo;
}


My question is : How to create a 2 or multiple events in 
$("select#stampa").change(function() for to create 2 or multiple query? 

[toc] | [next] | [standalone]


#8511

FromScott Sauyet <scott.sauyet@gmail.com>
Date2011-11-21 05:31 -0800
Message-ID<8704ba53-b8ef-4e8a-8d1d-886bd84a986d@a16g2000yqk.googlegroups.com>
In reply to#8508
Jesolo Sun wrote:

I'd suggest that your questions (if there are question lurking in
there :-) ) would best be addressed to a JQuery group or a PHP one.
But one quick note:

>   $("select#stampa").change(function(){
>     var stampa = $("select#stampa option:selected").attr('value');
>     // ...
>   });

This is cleaner, and I think it would work equally well:

    $("select#stampa").change(function(){
      var stampa = $(this).val();
      // ...
    }

  -- Scott

[toc] | [prev] | [next] | [standalone]


#8517

FromGregor Kofler <usenet@gregorkofler.com>
Date2011-11-21 23:32 +0100
Message-ID<jaejha$i1j$1@dont-email.me>
In reply to#8511
Am 2011-11-21 14:31, Scott Sauyet meinte:
> Jesolo Sun wrote:
> 
> I'd suggest that your questions (if there are question lurking in
> there :-) ) would best be addressed to a JQuery group or a PHP one.
> But one quick note:
> 
>>   $("select#stampa").change(function(){
>>     var stampa = $("select#stampa option:selected").attr('value');
>>     // ...
>>   });
> 
> This is cleaner, and I think it would work equally well:
> 
>     $("select#stampa").change(function(){
>       var stampa = $(this).val();
>       // ...
>     }

Out of curiosity:

Wouldn't

$("select#stampa").change(function(){
  var stampa = this.value;
}

suffice?

Gregor

-- 
http://vxweb.net

[toc] | [prev] | [next] | [standalone]


#8518

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2011-11-22 01:12 +0100
Message-ID<77765214.TbjAYTqD3W@PointedEars.de>
In reply to#8517
Gregor Kofler wrote:

> Am 2011-11-21 14:31, Scott Sauyet meinte:
>> Jesolo Sun wrote:
>> […]
>>>   $("select#stampa").change(function(){
>>>     var stampa = $("select#stampa option:selected").attr('value');
>>>     // ...
>>>   });
>> 
>> This is cleaner, and I think it would work equally well:
>> 
>>     $("select#stampa").change(function(){
>>       var stampa = $(this).val();
>>       // ...
>>     }

Those two approaches are _not_ equivalent, and the second one would 
certainly _not_ work equally well.  We have discussed the difference between 
the value of a selected `option' and the value of a `select' so often here 
that I have lost count.

> Out of curiosity:
> 
> Wouldn't
> 
> $("select#stampa").change(function(){
>   var stampa = this.value;
> }
> 
> suffice?

For that matter, wouldn't

  document.getElementById("stampa").onchange = function () {
    var stampa = this.value;
  };

or even

  <select name="stampa" onchange="…">
    …
  </select>

?

Answer: Nooo.  Neither wouldn't be k€wL enough!!" (far too efficient and 
compatible ;-))


PointedEars
-- 
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee

[toc] | [prev] | [next] | [standalone]


#8527

FromScott Sauyet <scott.sauyet@gmail.com>
Date2011-11-22 06:54 -0800
Message-ID<2e061c10-c38b-4d04-96e7-d33643ccade9@gi1g2000vbb.googlegroups.com>
In reply to#8518
Thomas 'PointedEars' Lahn wrote:
> Gregor Kofler wrote:
>> Am 2011-11-21 14:31, Scott Sauyet meinte:
>>> Jesolo Sun wrote:
>>> […]
>>>>   $("select#stampa").change(function(){
>>>>     var stampa = $("select#stampa option:selected").attr('value');
>>>>     // ...
>>>>   });
>
>>> This is cleaner, and I think it would work equally well:
>
>>>     $("select#stampa").change(function(){
>>>       var stampa = $(this).val();
>>>       // ...
>>>     }
>
> Those two approaches are _not_ equivalent, and the second one would
> certainly _not_ work equally well.  We have discussed the difference between
> the value of a selected `option' and the value of a `select' so often here
> that I have lost count.

Really?  I'm surprised because I don't recall it being discussed in
the two years I've been reading.  I certainly don't read every post,
and could well have missed one, but if it were so common, I would have
thought I'd have seen it.  Odd.

Except in the case of multiple selections, I don't know what the
difference would be.  Would you be willing to explain?  In the case of
multiple selection, the approach I suggested would return an array of
the selected values, whereas the original would only return the first
one.  I think that would be an improvement, but YMMV.  What other
differences are there?

> [ ... ]
> For that matter, wouldn't
>
>   document.getElementById("stampa").onchange = function () {
>     var stampa = this.value;
>   };
> [ suffice?]
>
> Answer: Nooo.  Neither wouldn't be k€wL enough!!" (far too efficient and
> compatible ;-))

Am I right that this would only show at most the first selection in
multi-select mode?  I know that's the case in the browsers I've
tested, but I have only tested a few recent browsers.  And in IE8,
would that even show any value?

  -- Scott

[toc] | [prev] | [next] | [standalone]


#8588

FromScott Sauyet <scott.sauyet@gmail.com>
Date2011-11-23 18:16 -0800
Message-ID<ef6a8d1a-18a8-4e87-8d79-dab25fb345c8@n14g2000vbn.googlegroups.com>
In reply to#8517
Gregor Kofler wrote:
> Am 2011-11-21 14:31, Scott Sauyet meinte:
>>>   $("select#stampa").change(function(){
>>>     var stampa = $("select#stampa option:selected").attr('value');
>>>     // ...
>>>   });
>
>> This is cleaner, and I think it would work equally well:
>
>>     $("select#stampa").change(function(){
>>       var stampa = $(this).val();
>>       // ...
>>     }

> $("select#stampa").change(function(){
>   var stampa = this.value;
> }

I don't think that works in IE (at least <9).

  -- Scott

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web