tags:

views:

47

answers:

3

I want to create a textbox for the username But once he starts typing i need a small image with the requirements of username to be displayed dynamically ..

can anyone help me ??

+1  A: 

You can use the :focus psuedo class on the textbox to add styling when the box has focus.

You cannot do what you are asking without javascript though.

jimplode
He *might* be able to do this using `:focus` and `:after` but it's not a clean solution. JS is needed
Pekka
+1  A: 

Lets say A1 is your text box and X1 is your image:

<script>
    function txtChange(){
        a1=document.getElementById(a1);
        x1=document.getElementById(x1);
        if(a1.value.length>0) {
           x1.style['display'] = true;
        }
    }
</script>


protected void Page_Load(object sender, EventArgs e)
{
    a1.Attributes["onchange"] = "txtChange()";
}

Oh and I guess it's worth mentioning if you want it just when they focus (click on it) not when they add text you can change "onchange" to "onfocus"

Jacob Nelson
I'm confused, did you just use a Javascript variable inside your C# code?
Marko
No, the lines 'a1=document.getElementById(a1);' and 'x1=document.getElementById(x1);' make 'a1' and 'x1' reference C# controls (in this case textbox and image).
Jacob Nelson
How does this do it with css and html?? This is a javascript solution.
jimplode
A: 

Depending on the location of the image, can you do something like this:

html

<input class="my_textbox"><img src=""/>

and then, using ":focus" and css sibling selector:

css

input.my_textbox + img {
  display:none;
}
input.my_textbox:focus + img {
  display:block;
}
MonkeyBoo
please tell me you did not put an image inside a textbox.... that is just wrong!!
jimplode
err no, it's a sibling selector... The <img> tag is not inside the input. It's AFTER the input element.
MonkeyBoo