It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

onclick not working

onclick not working

Postby michaelgriffin on Sat Dec 04, 2010 7:20 am

Hi,

I am using this code to call a function. As soon as I insert the reference in the function it stops working. This is being called via AJAX request.

This works:

Code: Select all
$output .= "
    <td width='20%' nowrap='nowrap' class='results_column'><div align='center'><img src='$_ENV[home_www]/icon/delete.png' title='Delete User' onclick='javascript:deleteNow(])' style='cursor:pointer' width='16' /></div></td>
    ";


When adding the reference it stops working
Code: Select all
$output .= "
    <td width='20%' nowrap='nowrap' class='results_column'><div align='center'><img src='$_ENV[home_www]/icon/delete.png' title='Delete User' onclick='javascript:deleteNow($users[reference])' style='cursor:pointer' width='16' /></div></td>
    ";


Any help would be greatly appreciated!
michaelgriffin
 
Posts: 2
Joined: Sat Dec 04, 2010 7:15 am

Re: onclick not working

Postby webmaster on Sat Dec 04, 2010 9:55 am

There's a problem when adding one variable in another.

I quess it's PHP your using. There are two methods I use (might be more).

1. $variable = "Text text {$foo} text text!";
2. $variable . "Text text " . $foo . " text text!";



So, try this:
Code: Select all
$output .= "
    <td width='20%' nowrap='nowrap' class='results_column'><div align='center'><img src='$_ENV[home_www]/icon/delete.png' title='Delete User' onclick='javascript:deleteNow({$users[reference]})' style='cursor:pointer' width='16' /></div></td>
    ";
User avatar
webmaster
Site Admin
 
Posts: 2695
Joined: Tue Aug 17, 2004 1:07 pm
Location: Sweden

Re: onclick not working

Postby HotNoob on Sat Dec 04, 2010 11:38 am

you can also use single quotes instead of double quotes; infact i recomend that you use single quotes since it uses a lot less processing time, and reduces the number of script vulnerabilities.

Code: Select all
   
<?php
$output .= '
        <td width=\'20%\' nowrap=\'nowrap\' class=\'results_column\'>
            <div align=\'center\'>
                <img src=\''.$_ENV[home_www]/icon/delete.png.'\' title=\'Delete User\' onclick=\'javascript:deleteNow("'.$users[reference].'")\' style=\'cursor:pointer\' width=\'16\' />
            </div>
        </td>
        ';
?>

also, i belive that your problem was the lack of qoutes in the input, unless $users[reference] referes to the name of a variable.

well, i hope one of the solutions provided in this topic works for you.
HotNoob
100+ Club
 
Posts: 169
Joined: Sun May 02, 2010 1:38 am

Re: onclick not working

Postby michaelgriffin on Mon Dec 06, 2010 6:33 pm

thanks hotNoob! problem solved!
michaelgriffin
 
Posts: 2
Joined: Sat Dec 04, 2010 7:15 am


Who is online

Users browsing this forum: No registered users and 5 guests