0

Is it possible to make an image visible when I click in a form field using HTML / jQuery or JavaScript?

This is my form field (in Laravel):

<div class="form-group">

    {!! Form::label('twitter', 'Twitter:') !!}
    {!! Form::text('twitter', null, ['class'=>'form-control']) !!}

</div>

The html part:

<a href="http://ss">
    <img width="16"
    src="https://s3.amazonaws.com/htmlsig-assets/round/twitter.png" alt="Twitter">
</a>

2 Answers 2

1

Give the link an ID, hide it using CSS

#linkId { display:none }

and do

$(function() {
 $(".form-control").on("click",function() {
   $("#linkId").show();
 });
});

To remove if empty:

$(function() {
 $(".form-control").on("focus, keyup",function() {
   $("#linkId").toggle(this.value!="");
 });
});
Sign up to request clarification or add additional context in comments.

1 Comment

This is clearly answer. And In case I want to dismiss the image if All character in the form were deleted, how to do that? Thank you very much.
1

Initially keep hidden class at your image if you are using bootstrap and when you click on any form field remove hidden class from img tag.

And if you are not using bootstrap then same can be achieved using css.

Suppose your anchor tag has class hidden.

$("input").on("focus", function() {
    $(a).removeClass("hidden");
 }

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.