Prasanth A R
Prasanth A R

Reputation: 4174

Inside jquery function html href code not working properly

the problem was in the line

  $('<td></td>').val(item['id']).html(
        '<a href="edit.html?id'='+sid'">Edit</a>'),alert(sid+"Id2:"+item['id']),
                            

here the alert is getting clearly.. but in browser the path shows

//localhost:8080/sample/teacher/edit.html?id'=sid'

here not shows the value of sid that is id 41 i want to show the link as

localhost:8080/sample/teacher/edit.html?id=41 or any other dynamic id value

i don't know why this happen the code is not right

Here var sid is an array & push value id to array.. the alert shows the value of sid & item['id'] correctly.

   $.each(responseData, function(index, item) {

        var sid = [];
                                
        $('#student').append(           
        $('<td></td>').val(item['id']).html(
            item['name']), 
    
        $('<td></td>').val(item['id']).html(
            item['phoneNo']),

            sid.push(item['id']),

        $('<td></td>').val(item['id']).html(
            '<a href="edit.html?id'='+sid'">Edit</a>'),alert(sid+"Id2:"+item['id']),

        $('<td></td>').val(item['id']).html(
                '<button onclick="lightbox1_open();">Delete</button>'),
        $('<br />').val(item['id']).html(
            item['']));         
        
    });

if you know the answer please share here...

Upvotes: 0

Views: 138

Answers (3)

Prateek
Prateek

Reputation: 6975

Use like this

'<a href="edit.html?id=' + sid + '">Edit</a>'

Upvotes: 2

Rituraj ratan
Rituraj ratan

Reputation: 10388

change id'='+sid'" this by id='+sid+'"

$('<td></td>').val(item['id']).html('<a href="edit.html?id=' + sid +'">Edit</a>');

Upvotes: 2

Arun P Johny
Arun P Johny

Reputation: 388416

Looks like the string concatenation is the problem, try

$('<td></td>').val(item['id']).html('<a href="edit.html?id=' + sid + '">Edit</a>')

Upvotes: 3

Related Questions