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!

9
  • 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? Commented Dec 7, 2011 at 1:21
  • can you show us this with php code around, because we don't know from where this comes: $row['numero'] Commented Dec 7, 2011 at 1: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 Commented Dec 7, 2011 at 1:26
  • 1
    more information would help us give you a solution Commented Dec 7, 2011 at 1:27
  • 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; Commented Dec 7, 2011 at 1:38

2 Answers 2

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?

Sign up to request clarification or add additional context in comments.

Comments

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;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.