1

ive got some answers from the search but my function is still not running

my code

<a href="javascript:;" onclick='<%# "search(" + Eval("Name") + ");" %>'><%# Eval("Name") %></a></li>

function

    function search(val) {
        alert(val);
        searchPagingTable(val, '#tblUsers');
    }

the html looks like

<a onclick="search(Fred);" href="javascript:;">

console error

SCRIPT5009: 'Fred' is undefined 

i think i need to get the quotes around the string, but if i put single quotes in the aspx, that fails too with a different error

Thanks for any help

2 Answers 2

1

do it like so:

onclick='<%# "search(\"" + Eval("Name") + "\");" %>'>

adding the escaped quotes will fix it.

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

2 Comments

But when I tried this I got something like this func(&quot;VALUE&quot;). Any Ideas?
something is parsing the quotes. I would need more info to know.
0

Try escaping the quotes around the string.

<a href="javascript:;" onclick='<%# "search(\'" + Eval("Name") + ");"\' %>'><%# Eval("Name") %></a></li>

By the looks of things, you were trying to call the 'search' function with a variable called 'Fred' as the argument, whereas you want to provide a string with the content set to 'Fred' as the argument. Correct me if I'm wrong.

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.