0

how to insert this javascript code :

thejavascript

<A HREF="javascript:void(0)" onclick="window.open('welcome.html','welcome')"> </A>

inside img src in php

<img src="http:'.$iv[$j].'.jpg" height="220" width="200"  alt="Image '.ucwords($kw).'" "thejavascript">

Thanks

4 Answers 4

2

You can use this jQuery script to add and onClick event in your balise img but you must adding an attribute id into your image. An id must be unique in your html page.

$("img#idImage").click(function({
    window.open('welcome.html','welcome');
}));

$kw = $ucwords($kw);
"<img id='idImage' src='http:{$iv[$j]}.jpg' height='220' width='200' alt='Image {$kw}' />";

But the best will be to separate attributes height and width into a CSS stylesheet.

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

1 Comment

$("img#idImage") can just be $("#idImage") since it's unique anyway.
1

Insert the following HTML outside PHP brackets and it should work according to the way you posted it. I'm making a few assumptions, one being that the link you posted wraps the image code and that the PHP variables turn the image into valid code.

<a href="javascript:void(0);" onclick="window.open('welcome.html','welcome')">
    <img src="http:<?=$iv[$j]; ?>.jpg" height="220" width="200"  alt="Image <?=ucwords($kw); ?>">
</a>

Comments

0

More simple, replace "thejavascript" (with the "") by :

onclick="window.open(\'welcome.html\',\'welcome\')"

Comments

0

A bit different approach, onclick event is on img tag.

$javascript="window.open('welcome.html','welcome')";

$img='<img src="http:'.$iv[$j].'.jpg" height="220" width="200"  onclick="'.$javascript.'">';

echo $img;

Comments

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.