Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm trying to make my Image Input pass a URL into a Javascript function using OnClick, however when I click on the input it does nothing. The code I am using is in PHP, and it echo's out a string with HTML tags in it.

echo "<input type=\"image\" onclick=\"imgp(\'" . $url .  "\')\" src=\"" . $url . "\" style=\"max-width: 20%; max-height: 20%\" /><br />";

The function that is getting called is as follows:

function imgp(url){
            if(url != null){
                var text = document.getElementById("body").value + "[img]" + url + "[/img]";
                document.getElementById("body").value = text;
                imgpopup();
            }
        }
share|improve this question
    
before using echo to print the html test the function using normal html –  Pradyut Bhattacharya Mar 7 '14 at 19:24

1 Answer 1

up vote 0 down vote accepted

As I can't test with the code you posted, try to do the following:

echo '<input type="image" onclick="imgp(\" . $url . '\')" src="' . $url . '" style="max-width: 20%; max-height: 20%" /><br />';

If you use simple quote ('), inside the echo, you can use the double quote (") without using (), but instead, you need to use only with ('), and vice-versa.

share|improve this answer
    
The {$url} thing doesn't seem to be outputting what it's supposed to... –  ProgrammingTurtle Mar 7 '14 at 19:35
    
Using echo '<input type="image" onclick="imgp(\'' . $url . '\')" src="' . $url . '" style="max-width: 20%; max-height: 20%" /><br />'; Seemed to work, update your code and I'll mark it as an answer. –  ProgrammingTurtle Mar 7 '14 at 19:37
    
There you go, done! Glad to help –  Leandragem Mar 7 '14 at 19:42
    
Merci, helped a lot! –  ProgrammingTurtle Mar 7 '14 at 19:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.