Jump to content

How to add onclick=“return false” in php


tazeha

Recommended Posts

I use java script code to disable click on link in php

but not working

onclick="return false"

I use tow way for add java script code to php link but both not working..

First way:

 $data .= '<td bgcolor="FFFFCC">'."<a href='http://priceha.ir/' onclick=\"return false\">.$row2->model.</a>".'</td>';

The second way:

$data .= '<td bgcolor="FFFFCC">'."<a href='http://priceha.ir/' onclick='return false'>.$row2->model.</a>".'</td>';
Edited by tazeha
Link to comment
Share on other sites

Both of those examples should work. If they're not working then perhaps you're not actually printing $data to the page. I'd have to see your page to figure out why it's not working.

 

The bgcolor attribute is not standard, you should be using CSS to give a background color. You also have forgotten the # symbol next to the hexadecimal code, at the very least it should be bgcolor="#FFFFCC"

Link to comment
Share on other sites

Do you want a period either side of $row2->model? because you have not escaped html text string, it should be

$data .= '<td bgcolor="#FFFFCC">'."<a href='http://priceha.ir/''>http://priceha.ir/' onclick=\"return false\">".$row2->model."</a>".'</td>';

If you wish to retain html double quotes without escaping all the time (however if passing string value to js function you will need to escape single quotes) use single quotes for html string

$data .= '<td bgcolor="#FFFFCC"><a href="http://priceha.ir/" onclick="return false">'.$row2->model.'</a></td>';
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...