| | |
java script help want to use it differently
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jun 2005
Posts: 3
Reputation:
Solved Threads: 0
Need your help in javascript
I am using following script for image over (to display another image)
<html>
<img src="mobilesmallimage.jpg" name="ShowRoom" width="129" height="96" onMouseOver=" ShowPic(name,'mobilebigimage.jpg') " onmouseout="ShowPic(name,'mobilesmallimage.jpg')" border="0"> </a>
I am sending 2 parameters
1. Name of image - variable name
2. Name of image to be displayed
Using following javascript
<javascript>
<script language="javascript"> function ShowPic(imgname, sImage) {
var Imgname=imgname;
var sImage = sImage ; j='document.' +Imgname+'.src = '+sImage; alert(j); eval('document.' +Imgname+'.src = '+sImage);
; } </script>
alert shows me correct value i.e. the image to be dispayed however the image is not displayed here
However following set of code works fine
<img src="mobilesmallimage.jpg" name="ShowRoom" width="129" height="96" onMouseOver="ShowPic('mobilebigimage.jpg')" onmouseout="ShowPic('mobilesmallimage.jpg')" border="0"> </a>
and javascript
<script language="javascript"> function ShowPic(sImage) {
sImage = sImage ; document.ShowRoom.src = sImage; } </script>
Please help
Thanks in advance
I am using following script for image over (to display another image)
<html>
<img src="mobilesmallimage.jpg" name="ShowRoom" width="129" height="96" onMouseOver=" ShowPic(name,'mobilebigimage.jpg') " onmouseout="ShowPic(name,'mobilesmallimage.jpg')" border="0"> </a>
I am sending 2 parameters
1. Name of image - variable name
2. Name of image to be displayed
Using following javascript
<javascript>
<script language="javascript"> function ShowPic(imgname, sImage) {
var Imgname=imgname;
var sImage = sImage ; j='document.' +Imgname+'.src = '+sImage; alert(j); eval('document.' +Imgname+'.src = '+sImage);
; } </script>
alert shows me correct value i.e. the image to be dispayed however the image is not displayed here
However following set of code works fine
<img src="mobilesmallimage.jpg" name="ShowRoom" width="129" height="96" onMouseOver="ShowPic('mobilebigimage.jpg')" onmouseout="ShowPic('mobilesmallimage.jpg')" border="0"> </a>
and javascript
<script language="javascript"> function ShowPic(sImage) {
sImage = sImage ; document.ShowRoom.src = sImage; } </script>
Please help
Thanks in advance
Try this:
You are probably in dire need of debugging feedback; lots of people seem to think they have to write JavaScript using solely their imagination. I recommend loading up your page in Firefox and looking at Tools > Error Console.
eval('document.' +Imgname+'.src = \''+sImage+'\''); You are probably in dire need of debugging feedback; lots of people seem to think they have to write JavaScript using solely their imagination. I recommend loading up your page in Firefox and looking at Tools > Error Console.
Chaos
Lost Souls: text based RPG
MUDseek: MUD gaming search
Lost Souls: text based RPG
MUDseek: MUD gaming search
•
•
Join Date: Jun 2005
Posts: 3
Reputation:
Solved Threads: 0
Dear Sir
I appreciate your valued feed back
I traied eval (in javascript function)
May try in html part ?
Let me elaborate you why am asking this :
I am writing code for cms (Content Management software)
In this we could different image on the mouse over
However if data is read from database then I need to dynamically give values for name and images to be displayed on mouse over and on mouse out
to simulate this I had changed the javascript given to you
Hope this clarifies
I appreciate your valued feed back
I traied eval (in javascript function)
May try in html part ?
Let me elaborate you why am asking this :
I am writing code for cms (Content Management software)
In this we could different image on the mouse over
However if data is read from database then I need to dynamically give values for name and images to be displayed on mouse over and on mouse out
to simulate this I had changed the javascript given to you
Hope this clarifies
No, that doesn't really tell me anything useful.
What I'm saying in my post is that you need to wrap the target URL you're changing the image's source to in single quotes. You're constructing an eval that looks like this:
This should be what you're seeing in your alerts. This will not work. You need to be doing this:
The replacement eval-construction code I posted before is a way to do this.
The reason that nothing like this had to be done before, but has to be done now, is that you're changing methodologies to using an eval, which means that you have to make a string that interprets as valid JavaScript.
But then, the whole methodology you're using isn't really such a good idea. So here's another suggestion for what to do instead of any of this:
If I'm not horribly mistaken, that will work far better and with much less fuss.
What I'm saying in my post is that you need to wrap the target URL you're changing the image's source to in single quotes. You're constructing an eval that looks like this:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
document.someName.src = mobilebigimage.jpg
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
document.someName.src = 'mobilebigimage.jpg'
The reason that nothing like this had to be done before, but has to be done now, is that you're changing methodologies to using an eval, which means that you have to make a string that interprets as valid JavaScript.
But then, the whole methodology you're using isn't really such a good idea. So here's another suggestion for what to do instead of any of this:
javascript Syntax (Toggle Plain Text)
<javascript> <script language="javascript"> function ShowPic(imgname, sImage) { document[imgname].src = sImage; } </script>
If I'm not horribly mistaken, that will work far better and with much less fuss.
Chaos
Lost Souls: text based RPG
MUDseek: MUD gaming search
Lost Souls: text based RPG
MUDseek: MUD gaming search
![]() |
Similar Threads
- designing an operating system (Computer Science)
- jsp login code (JSP)
- help my computer is being hacked ! (Viruses, Spyware and other Nasties)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: How to Create Web Spider / Crawler?
- Next Thread: Ajax help => Scriptculous
| Thread Tools | Search this Thread |
ajax ajaxcode ajaxexample ajaxhelp ajaxjspservlets animate automatically beta box browser bug calendar captchaformproblem checkbox child class close column createrange() css cursor date debugger dependent disablefirebug dom download dropdown editor element embed engine error events explorer ext file form forms getselection google gwt gxt hiddenvalue highlightedword hint html htmlform ie7 ie8 iframe images internet java javascript javascripthelp2020 jawascriptruntimeerror jquery jsf jsfile jump libcurl math media microsoft mimic object onmouseoutdivproblem onreadystatechange parent paypal pdf php player position post problem programming progressbar regex runtime scroll search security select shopping size software sql text textarea unicode w3c web website window windowofwords windowsxp wysiwyg \n





