1

EDIT:

With the hints on the responses i got to know that name isn't a valid attribute for div tag, but it's for select.

function modifica(estado,numero){
    alert(numero);
    $.ajax({
    type: "GET",
    datatype: "html",
    url: "icallverifica.php",
    data: {
    estado : estado,
    modifica : "1" ,
    numero : numero
    },
    success: function(data) {
        alert(data);
    }
    });
}

So, i want to get multiple attributes at once using onchange:

if($valor == 0){
    mysql_select_db("iloja_icall", $con);
    $result1 = mysql_query("SELECT * FROM icall WHERE verifica='0'");
    while($row = mysql_fetch_array($result1)){
    echo $row['numero'].'<select id="optin" name="'.$row['numero'].'" onchange="modifica(this.value,this.name)">
  <option value="chamada">Chamada</option>
  <option value="atendeu">Atendeu</option>
  <option value="atendeunao">Nao atendeu</option>
  <option value="engano">Engano</option>
</select>';
    echo '<br>';
    }
}

THIS COMBO IS NOW WORKING FLAWLESSLY :D THANK YOU SO MUCH GUYS, this is why i love stackoverflow :)

Shouldn't this work?

Thanks so much guys!

Souza
  • 1,124
  • 5
  • 19
  • 44
  • 1
    Why not just use `onchange="modifica(this)"` then you can get all it's properties from within your `modifica` function? Or just pass the `id` of the `select` and use javascript to get what you need? – Aaron W. Dec 07 '11 at 01:21
  • can you show us this with php code around, because we don't know from where this comes: `$row['numero']` – noob Dec 07 '11 at 01:22
  • "modifica(this.value,this.name)" is incorrect, this returns the select which has no "name" attribute, what you want to do is use "modifica(this)" and then call $( this ).parent().attr( "name" ) to get the name of the parent div of the select –  Dec 07 '11 at 01:26
  • 1
    more information would help us give you a solution –  Dec 07 '11 at 01:27
  • Did you mean values, not attributes? This will only give you a single value and the select tag's name once the selection is made. – Michael Bunch Dec 07 '11 at 01:29
  • I believe the wants the name of the "div" which is parent of "select", because the div tag has "name" but the select has only "id" –  Dec 07 '11 at 01:30
  • 1
    I missed that, good catch. Not to nit-pick, but 'name' is an invalid attribute for a div tag. Should be switched to 'id'. This also removes the need to call .attr('name') and instead use: $( this ).parent().id; – Michael Bunch Dec 07 '11 at 01:38
  • I love SO, every day I learn something new, thank you, didn't knew that "name" is a invalid attribute for div. –  Dec 07 '11 at 01:40
  • @MichaelBunch thank you so much, please add a response with the comment you made so i can select as the right answer. – Souza Dec 07 '11 at 01:56

2 Answers2

2

Based on the tags for this question, I see you're using jQuery.

// assuming you're passing "this" to function
function modifica(me) {
    var id = me.parentNode.id; // or $(me).parent().attr('id'); etc
}

Additionally, you could just remove the onchange attribute and set it with an even listener (recommended):

$('#optin').change(function(e) {
    // code here
    var option = $(this).val(); // current selected option for example

    // if you want to get ALL attributes of an element:
    var attribs = $(this)[0].attributes; // or $('#elementID')... etc
});

If you want to iterate (loop) through all of an element's attributes, then check out this: How to iterate through all attributes in an HTML element?

Community
  • 1
  • 1
Yes Barry
  • 9,514
  • 5
  • 50
  • 69
0

The 'name' is an invalid attribute for a div tag. Should be switched to 'id'. This also removes the need to call .attr('name') and instead use:

$(this).parent().id;