/    Sign up×
Community /Pin to ProfileBookmark

Javascript help (deleting a picture)

This is my first post. I’m very glad to have found this forum!

I’m trying to modify this script:

<script language=”javascript”>
<!–

/*Combo Box Image Selector:
By JavaScript Kit ([url]www.javascriptkit.com[/url])
Over 200+ free JavaScript here!
*
/

function showimage()
{
if (!document.images)
return
document.images.pictures.src=
document.mygallery.picture.options[document.mygallery.picture.selectedIndex].value
}
//–>
</script>

<table border=”0″ cellspacing=”0″ cellpadding=”0″>
<tr>
<td width=”100%”><form name=”mygallery”><p><select
name=”picture” size=”1″ onChange=”showimage()”>
<option selected value=”me.gif”>Picture of me</option>
<option value=”myaunt.gif”>Picture of my aunt</option>
<option value=”brother.gif”>Picture of my brother</option>
</select></p>
</form>
</td>
</tr>
<tr>
<td width=”100%”><p align=”center”><img src=”me.gif” name=”pictures” width=”99″
height=”100″></td>
</tr>
</table>

What I would like to do is make OPTION one “None” by default. How do I modify the script to delete the picture if “None” is selected?

You may see what I am doing here (at the bottom of the screen)

[url]http://legaljam.com/calendar/admin.pl[/url]

Thanks for any help!

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@artemisSep 12.2004 — [font=technical][size=3]try this

[font=monospace][size=5]
[code=php]
function showimage(){
if(!document.images){
return false;
}
p=document.mygallery.picture.options[document.mygallery.picture.selectedIndex].value;
if(p=='none'){
document.images.pictures.style.display='none';
}else{
document.images.pictures.style.display='block';
document.images.pictures.src=p;
}
}
[/code]
[/size][/font][/size][/font]
Copy linkTweet thisAlerts:
@KeithauthorSep 13.2004 — Thank You! It works great.
Copy linkTweet thisAlerts:
@KorSep 13.2004 — a DOM full variant:
[code=php]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script language="JavaScript" type="text/JavaScript">
function showimage(s,v){
obj = document.getElementById('pictures');
if(s==0){
obj.style.display='none';
}
else{
obj.setAttribute('src',v);
obj.style.display='block';
}
}
onload=function(){showimage(0)}
</script>
</head>

<body>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="100%"><form name="mygallery"><p><select
name="picture" size="1" onchange="showimage(this.selectedIndex,this.value)">
<option selected value="none">None</option>
<option value="me.gif">Picture of me</option>
<option value="myaunt.gif">Picture of my aunt</option>
<option value="brother.gif">Picture of my brother</option>
</select></p>
</form>
</td>
</tr>
<tr>
<td width="100%"><p align="center"><img src="me.gif" id="pictures" width="99"
height="100"></td>
</tr>
</table>
</body>
</html>
[/code]
×

Success!

Help @Keith spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.13,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,
)...