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 MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Controlling an Image's URL from another object

Status
Not open for further replies.

Isadore

Technical User
Feb 3, 2002
2,167
US
Greetings Java fans. I love this forum because of the attention it gets and tho I cannot help you guys out that much I do spend time on a couple of other forums helping others, so thanks for your hard work and dedication.

I have a simple problem that is killing my time (10 hours now). What I have to do is rather simple. On a datagrid in ASP.NET I have a hyperlink field. From that hyperlink field, which gets fired onClick, I need to send down a new parameter for a chart on the same page, that is, change that images's URL (scr) based on the clicked selection.

What's the trick in Java to send the results of a hyperlinnk to an image and thereby call for the reloading of that image? This is a great technicque, just can't quite get a hold of it.

Thanks!
 
This is the Javascript forum isn't it?

You want to create Image objects in a global script space and assign them the url(s). This causes the browser to load them and store the objects in your variable. Then your click handler you set the elements 'src' propterty equal to the 'src' property of the Image object:

var myImage = new Image();
myImage.src = "
function clickHandler(){
document.all.foobar.src = myImage.src;
}

Hope this helps
-pete
 
Pete: Thanks for getting back. Yes, this problem involves ASP.NET but its a javascript function that is holding up the finishing of this. The idea, as mentioned is to change the src after selecting a parameter in a hyperlink grid column. No luck as of yet. The three interatcting members are:

Template Column (Date, Single column datagrid)

<ItemTemplate>
<asp:HyperLink
id=&quot;HyperLink1&quot;
Text='<%# Databinder.eval container.dataitem, &quot;SampleDate&quot;, &quot;{0:d}&quot;)%>'
NavigateUrl=&quot;javascript:swap('NewProfilesCharts.aspx?date=
<%# Databinder.eval (container.dataitem, &quot;SampleDate&quot;, &quot;{0:d}&quot;)%>');
runat=&quot;server&quot;
</asp:HyperLink>
</ItemTemplate>

JavaScript:

<script=javascript>
<!-- Hide script from non java browsers
function swap(newimage){
var fileName = newImage.toString()
document.all.myimage.src = fileName
}
// stop hiding -->
</script>

Image Tag:

<asp:Imagebutton id=&quot;myimage&quot; runat=&quot;server&quot; Height=&quot;350px&quot; Width=&quot;500px&quot; src=&quot;.\images\Blufill.png&quot;/>

I'm sure the solution is close to this; just can't get it to come together. I've also posted at the ASP.NET forum; guess everyone is busy over the holidays.


 
Just about have this one wrapped up. Its a nice technique and should be straight forward. Down to &quot;one&quot; error, and it comes from a line in the Javascript function. Here's the &quot;near finished&quot; product (when I get the thing working I'll post a link on the net - its a nice platform because it doesn't require a post-back, nor all the image storing in mouseover; it just sends back for a binary delivery of the next chart.

First: DataGrid

The following is working perfectly (hyperlink column):

<asp:DataGrid id=&quot;dgSampleDate&quot; ...runat=&quot;server&quot;>
<Columns>
<asp:HyperLinkColumn
HeaderText=&quot;<b><i>Sample Date</b></i>&quot;
DataNavigateUrlField=&quot;SampleDate&quot;
DataNavigateUrlFormatString=&quot;javascript:delsrc({0:d});&quot;
DataTextField=&quot;SampleDate&quot;
DataTextFormatString={0:d}>
</asp:HyperLinkColumn>
</Columns>
</asp:DataGrid>

...I abandoned the Template Column as it was not necessary; also, it seemed to interfer with the Javascript execution. At any rate, the grid seems to be working fine. Also, the Image tag seems ok, q.v.,

Second: The Image tag

<IMG src=&quot;.\images\Blufill.png&quot; name=&quot;myimage&quot; border=&quot;0&quot; Height=&quot;310&quot; Width=&quot;470&quot; >

...which is fine, and finally, the &quot;last problem&quot;, q.v,

Third: The Javascript function (to pass the new URL)

<script language=javascript>
function delsrc(Date){
document.images.myimage.src = 'NewProfilesCharts.aspx?date=' + Date;}
</script>

...the last error I recieve is from the document.images... line. A javascript error appears saying that an &quot;ojbect&quot; is missing. Something is not quite right with the Javascript function line - seems to be breaking on the word document from what I can tell. I've tried substituting images for all etc, but can't get past this last java error message.
 
Tried that. Both id and Name in the image tag make no difference. Also in the document.images.myimage.src and document.all.myimage.src both seem to operate the same under these conditions. I have put a lot of time in this problem, ready to upload to the internet for people to use, but this last error has it sabotaged. The error, exactly reads:

Char: 1
Line: 75 (that's the line with document.images...)
Error: Object expected

Its a puzzle for sure. I've been working on this for 4 or 5 days (off and on) and now down to single hang up. Of course, when your that close its only a matter of time.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top