Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

image change after validation

Status
Not open for further replies.

flnMichael

Programmer
Nov 13, 2003
96
US
Hey,
I have this piece of code in my codebehind (C#) for generating a tablecell with an image:


Code:
TableCell PassFailImage = new TableCell();

HyperLink hlnk = new HyperLink();
hlnk.ID = "passfaillight" + max_parm_count.ToString();
hlnk.ImageUrl = "images/whiteball.gif";
hlnk.Controls.Add(hlnk);
PassFailImage.Controls.Add(hlnk);

Now, I have another piece of code in the same codebehind. This is another textbox generation that has an onblur. The function does the right calculations and gets the right value at the end of the function, but I want the image to change. I may be doing the initial image generation wrong, with it being a new Hyperlink when I don't need it to be a hyperlink, I just wanted the image and that's the only way I could get it to show on the page.

Here's the function call:


Code:
TableCell Value = new TableCell();

TextBox _Value = new TextBox();
_Value.Width = 80;
_Value.ID = "Value" + max_parm_count.ToString();
_Value.Attributes["onblur"] = "validate2(this.form, " + max_parm_count.ToString() + ", passfaillight" + max_parm_count.ToString() + ", " + max_parms + ");";

Value.Controls.Add(_Value);

and here's some of the function:


Code:
function validate2(form, index, passfail, max_parms)
{
  pic = "images/whiteball.gif";
..
..
  passfail.src = pic;

I guess all I want to know is how to get the image in a tablecell the right way, then pass it in the function and change it when the function is through.

Any help would be appreciated.

Thanks
Mike
 

I guess all I want to know is how to get the image in a tablecell the right way

If you want to know how to do this without a hyperlink, you should ask int he C# forum (assuming you want to know how to do it in C#), or ask in the HTML forum (if you want to do it in good old HTML).

As for the validate2 function, where is "passfail" getting set? If it doesn't point to a valid image, nothing will ever change.

There are many ways of setting an image using JS, but one simple way is to give your image an ID:

Code:
<img id="myImg" src="wibble.gif />

and then use the getElementById method:

Code:
document.getElementById('myImg').src = 'newSrc.gif';

Hope this helps,
Dan


[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top