I want to add custom link that is stored in a value inside a php button. How do I do it?
I am trying to get this sorted how ever its not doing it, it just returns nothing or sometimes returns the current page link instead. I am looking towards adding my $lnk to this code in href section.
This is what I have:
echo '<input class="btnnn-class" type=btnnn-class onClick=location.href="" .$lnk value="Contact Buyer">';
Where $lnk
is my link inside of it.
There is several typos in your code : you did not open and/or close quotes when needed. You have too surround your classes with double quotes and your onClick
value too. Inside it, the location href
is a string too that should be inside quotes.
Both php and javascript allow single and double quotes to delimitate a string, but you should use only double quotes for html attributes.
So:
'
for the whole echo
statement (but varaiables are not interpreted inside single quotes), "
for the html attributes. '
for the javascript value, and escape it (becasue they are inside another php single quoted string). The code:
echo '<input class="btnnn-class" type="btnnn-class" onClick="window.location.href=\'' . $url . '\'" value="Contact Buyer">' ;
Or use double quotes for php and espace the html attributes ones, the variable will be interpreted:
echo "<input class=\"btnnn-class\" type=\"btnnn-class\" onClick=\"window.location.href=$url\" value=\"Contact Buyer\">" ;
Al Fonce told correct answer and described wel He forget one double quotes after $lnk . '\\'
echo '<input class="btnnn-class" type="btnnn-class" onClick="window.location.href=\'' . $lnk . '\'" value="Contact Buyer">' ;
Try this:
echo '<input class="btnnn-class" type="btnnn-class" onClick="window.location.href=\'$lnk\'" value="Contact Buyer">' ;
Because of the quotes, you are facing the problem.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.