2

I'm having an issue where i populate a button with an onclick, i see that in the HTML once its populated (after the document is first loaded) the onclick is there, but it wont trigger the function, heres the PHP code:

while($row = sqlsrv_fetch_array($result))
{
    echo('<div class="row">
    <div class="col"><span>Company Name: ' . $row['CompanyName'] . '</span></div>
    <div class="col"><span>Telephone: ' . $row['CustomerNumber'] . '</span></div>
    <div class="col"><span>Access Code: ' . $row['AccessCode'] . '</span></div>
    <div class="col"><span>Active: ' . $row['Active'] . '</span></div>
    <input type="button" value="Delete" onClick="javascript:delete(this);"></input></div><br />');

The delete function is on the same page as the populated button (function delete(e){}), any ideas why it wouldn't trigger?

Note there are no JS errors and javascript is enabled (can call a function directly from the browser)

EDIT:

Heres 1 line from the HTML output:

    <br>
<div class="row">
<div class="col">
<span>Company Name: TBC</span>
</div>
<div class="col">
<span>Telephone: 354</span>
</div>
<div class="col">
<span>Access Code: </span>
</div>
<div class="col">
<span>Active: </span>
</div>
<input type="button" onclick="delete(this);" value="Delete">
</div>
7
  • 2
    you don't need the javascript: part there ;) Commented Feb 29, 2012 at 15:46
  • what's in your delete javascript function? Commented Feb 29, 2012 at 15:46
  • p.s. you should be using ',' (echo can take multiple arguments) instead of '.' (string concatenation) Commented Feb 29, 2012 at 15:47
  • 1
    Can you post the generated HTML? Commented Feb 29, 2012 at 15:59
  • Topener thanks, removed, no effect though. powtac sorry, rushed :) scibuff just an alert. I'll use the , instead but i dont belive this will affect this issue. Commented Feb 29, 2012 at 16:03

2 Answers 2

1

Remove the javascript: just leave: onclick="delete( this )"

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

2 Comments

Is this really an answer to the question?
I had already tried that (sorry i didn't mention), no luck at all, nothing triggers, the javacript function is as follows on the page where the button is populated: function delete(e) { alert("TRIGGERED"); } I do not get my alert box :(
-1

delete() is a reserved word in javascript, try changing the function name to deleteIt() or something else instead.

1 Comment

Thanks Niklas, it was because the function name was a reserved word! :) i'm referencing the button as in the JS for delete i use that to ref the parent node (and it's random ID) so i can delete it from the DB and from the DOM.

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.