Friday, May 6, 2011

$html-link() using onmouseover

Trying to use an onmouseover event

echo $html->link("Dashboard", 
     "/dashboard/index", 
     array("onmouseover" => "Tip('Test');") );

becomes

<a href="/dashboard/index" onmouseover="Tip(&#039;Test&#039;);">Dashboard</a>

How do I prevent the link function from removing the single quotes?

From stackoverflow
  • This should work:

    echo $html->link("Dashboard", 
         "/dashboard/index", 
         array("onmouseover" => "Tip('Test');"),
         array('escape' => false));
    
    Jack B Nimble : added onclick="return confirm('Array');" after the onmouseover. It went into the confirm return true/false parameter of link.
  • Using Cake 1.2, this should definitely work:

    echo $html->link('Dashboard', '/dashboard/index',
    array("onmouseover" => "Tip('Test');"), null, false);
    

    The last parameter is the escape option. It defaults to true.

0 comments:

Post a Comment