Tudor
Tudor

Reputation: 633

Ajax with method load() for options value in select field

I have a problem with my select field, because I can't catch the value of an option, my code:

<form method="get" name="form1" > 
  <select id="rpc" onchange="$('#rpc').load('aja.province.php?cod=this.value')">

how can I send the value to the option in a PHP file with method GET?

Best Regards.

Upvotes: 0

Views: 586

Answers (2)

Mike Brant
Mike Brant

Reputation: 71384

If you are using jQuery, I would suggest removing the inline stuff and just do something like this in your source:

$('#rpc').change( function () {
    var url = 'aja.province.php?cod=' + this.value;
    load(url, function () {
        // do whatever you need to do with returned value
    }
});

Note that your current in-line load() call is passing a literal string of this.value for the cod parameter.

Upvotes: 1

Arun P Johny
Arun P Johny

Reputation: 388316

$('#rpc').load('aja.province.php?cod=this.value') should be $('#rpc').load('aja.province.php?cod='+this.value).

this.value is not a string, it is a javascript expression.

Upvotes: 3

Related Questions