|
-
Sep 9th, 2003, 10:41 AM
#1
Thread Starter
Fanatic Member
[completly Resolved] javascript: change Picture OnClick argh.
Okay. Why the heck won't this work for me.
It works somewhat, but not 100%.
What I want is an image to change based on a drop-down value.
However, I'd be happy to just get it working for some hard-coded pictures.
Here's what I got as a test page, I plan on populating the drop down from a database later.
If you can supply some hints for using the value of the drop down, I'd appreciate that also.
(this will be an ASP page)
VB Code:
<script language="JavaScript">
function DoPic()
{
document.PutPicHere.src="Charts\0.jpg";
}
</script>
<html>
<body>
Hello, why don't your web page work? loser.
<table>
<tr>
<td><font face="arial">Choose One
<select name="MyPix" size=1 onClick="DoPic()">
<option value="0" selected>Choice Won</option>
<option value="1" >Choice Too</option>
</select>
</td>
<td>
<img name="PutPicHere" src="Charts\1.jpg">
</td>
</tr>
</table>
</body>
</html>
It gets as far as replacing my current 1.jpg with a nice red 'X',
so it's at least getting that far....
Yes, there is a dir called Charts,
Yes, there is a pic called 0.jpg in that dir.
I'm running on Personal web server, but that shouldn't matter.
I think I"m following examples I've seen for other questions...
Last edited by JPicasso; Sep 10th, 2003 at 10:32 AM.
Merry Christmas
-
Sep 9th, 2003, 01:20 PM
#2
Beside your HTML being completly outdated (<font> *shudder*), here's a nice way.
Code:
<script language="JavaScript">
function DoPic(s)
{
var val = s.options[s.selectedIndex].value;
document.PutPicHere.src=val;
}
</script>
<html>
<body>
Hello, why don't your web page work? loser.
<table>
<tr>
<td><font face="arial">Choose One
<select name="MyPix" size=1 onchange="DoPic(this)">
<option value="somepix.png" selected>Choice Won</option>
<option value="otherpix.png" >Choice Too</option>
</select>
</td>
<td>
<img name="PutPicHere" src="Charts\1.jpg">
</td>
</tr>
</table>
</body>
</html>
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Sep 9th, 2003, 01:29 PM
#3
Thread Starter
Fanatic Member
thanks dude.
Ya. my html is cut-and paste from my boss's old pages.
I generally just write apps for VB for stand-alone programs,
However, a project came up and I decided it would be best if I tried to keep my job. 
font? outdated? how else will mosaic know what characters to use?
-
Sep 9th, 2003, 02:14 PM
#4
Thread Starter
Fanatic Member
Doh!
I want to add a string contsant "Charts\" to the path in the function?
like :
VB Code:
var val = 'Charts\' & s.options[s.selectedIndex].value;
OR
document.PutPicHere.src='Charts\' & val;
I need to just have the drop down take the name of the file, but the
file is actually one directory in on the server.
Unterminated string constant?
I'm so clueless.
-
Sep 9th, 2003, 07:55 PM
#5
Fanatic Member
& is only for comparison in JavaScript. Use a + instead.
www.RealisticGraphics.net
Running VS.Net Enterprise & VB 6
Other Languages: JavaScript, VBScript, VBA, HTML, CSS, ASP, SQL, XML
MSN Messenger: kmsheff
-
Sep 10th, 2003, 01:23 AM
#6
And if you want a \ in a string you need to escape it:
"imgs\\myimg.png"
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Sep 10th, 2003, 07:02 AM
#7
Thread Starter
Fanatic Member
I should have just been a doctor instead of this funky program stuff.
Anyways, thanks to both of you.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|