tags:

views:

24

answers:

1

I'm creating the following div using javascript, task_id is an int and person_name is a string, why is my alert not working! when i send 2 integers, the alert works fine, when i send 2 strings the alert still doesn't work, what am i doing wrong?

'<div " onMouseOver="Drag(' + task_id + ',' + person_name +');"</div>'
.....


function Drag(id, name){
    alert(id + "   " + name);
}

thanks a million in advance

+1  A: 

You need to correctly add escaped string delimiters around the string, otherwise you're sending a variable with the name of person_name's value. Try:

'<div onMouseOver="Drag(' + task_id + ',\'' + person_name +'\');"></div>' 
Andy E
thanks a million, i tried \" instead of \' and it obviously didn't work, i'm still a beginner...
Lina
@Lina: You can't use the same string delimiter as the HTML attribute you're defining. If your attribute uses double quotes, your inner javascript must use single quotes (apostrophes) and vice versa.
Andy E