Menu
From a listbox I would like to generate differnet images (*.gif) and update (associate with the selection) an hyperlink accessible from the click of a button.
Please help.
Tx!
[code=php]<style type="text/css">
.fld {
padding:5px;
width:125px;
text-align:center;
}
.pic {
width:125px;
float:left;
text-align:center;
}
.lnk {
color:blue;
font-weight:bold;
}
.img {
width:65px;
height:65px;
}
</style>
<script type="text/javascript">
function newPic(elem,si) {
var lnk = elem[si].value;
var txt = elem[si].text;
var pic_src = elem[si].getAttribute('pic');
var anch = document.createElement('a');
anch.href = lnk;
anch.title = txt;
anch.className = 'lnk';
anch.appendChild(document.createTextNode(txt));
var pic = new Image();
pic.src = pic_src;
pic.alt = txt;
pic.className = 'img';
document.getElementById('pic').innerHTML = "";
document.getElementById('pic').appendChild(pic);
document.getElementById('pic').appendChild(document.createElement('BR'));
document.getElementById('pic').appendChild(anch);
}
</script>
<form method="post" action="script.pl" onsubmit="return false;">
<fieldset class="fld"><legend>Select a Picture</legend>
<select id="sports" name="sports" onchange="newPic(this,selectedIndex)">
<option value="http://mlb.com" pic="mlb.gif">MLB</option>
<option value="http://nhl.com" pic="nhl.gif">NHL</option>
<option value="http://nba.com" pic="nba.gif">NBA</option>
<option value="http://nfl.com" pic="nfl.gif">NFL</option>
</select>
</fieldset>
</form>
<div id="pic" class="pic">
</div>[/code]
Dr. Script[code=php]<form method="post" action="script.pl" onsubmit="onchange="newPic(this,selectedIndex);return false;">
<fieldset class="fld"><legend>Select a Picture</legend>
<select id="sports" name="sports">
<option value="http://mlb.com" pic="mlb.gif">MLB</option>
<option value="http://nhl.com" pic="nhl.gif">NHL</option>
<option value="http://nba.com" pic="nba.gif">NBA</option>
<option value="http://nfl.com" pic="nfl.gif">NFL</option>
</select>
<buttont type="submit">Show!</button>
</fieldset>
</form>[/code]
Is that what you need?[i]Originally posted by steelersfan88 [/i]Sorry about that.
[B][code=php]<form method="post" action="script.pl" onsubmit="newPic(this,selectedIndex);return false;">
[/B][/QUOTE]
<fieldset class="fld"><legend>Select a Picture</legend>
<select id="sports" name="sports">
<option value="http://mlb.com" pic="mlb.gif">MLB</option>
<option value="http://nhl.com" pic="nhl.gif">NHL</option>
<option value="http://nba.com" pic="nba.gif">NBA</option>
<option value="http://nfl.com" pic="nfl.gif">NFL</option>
</select>
<buttont type="submit">Show!</button>
</fieldset>
</form>[/code]
var anch = document.createElement('a');
anch.href = lnk;
anch.title = txt;
anch.className = 'lnk';
anch.appendChild(document.createTextNode(txt));
var pic = new Image();
pic.src = pic_src;
pic.alt = txt;
pic.className = 'img';
document.getElementById('pic').innerHTML = "";
document.getElementById('pic').appendChild(pic);
document.getElementById('pic').appendChild(document.createElement('BR'));
document.getElementById('pic').appendChild(anch);
[code=php]<style type="text/css">
.fld {
padding:5px;
width:145px;
text-align:center;
}
.pic {
width:145px;
float:left;
text-align:center;
}
.lnk {
color:blue;
font-weight:bold;
}
.img {
width:65px;
height:65px;
}
</style>
<script type="text/javascript">
function newPic(elem,si) {
var si = elem.selectedIndex
var lnk = elem[si].value;
var txt = elem[si].text;
var pic_src = elem[si].getAttribute('pic');
var anch = document.createElement('a');
anch.href = lnk;
anch.title = txt;
anch.className = 'lnk';
anch.appendChild(document.createTextNode(txt));
var pic = new Image();
pic.src = pic_src;
pic.alt = txt;
pic.className = 'img';
document.getElementById('pic').innerHTML = "";
document.getElementById('pic').appendChild(pic);
document.getElementById('pic').appendChild(document.createElement('BR'));
document.getElementById('pic').appendChild(anch);
}
</script>
<form method="post" action="script.pl" onsubmit="newPic(this.sports);return false;">
<fieldset class="fld"><legend>Select a Picture</legend>
Sport: <select id="sports" name="sports">
<option value="http://mlb.com" pic="mlb.gif">MLB</option>
<option value="http://nhl.com" pic="nhl.gif">NHL</option>
<option value="http://nba.com" pic="nba.gif">NBA</option>
<option value="http://nfl.com" pic="nfl.gif">NFL</option>
</select><BR>
<button type="submit">Show!</button>
</fieldset>
</form>
<div id="pic" class="pic">
</div>[/code]
Dr. Script var anch = document.createElement('button');
anch.onclick = function() {
window.location = lnk;
}
anch.setAttribute('type','button');
anch.className = 'lnk';
anch.appendChild(document.createTextNode(txt));[code]If you wnat the button to say the same thing, change the last line above to:[code]anch.appendChild(document.createTextNode('BUTTON TEXT HERE'));
Dr. Script0.1.9 — BETA 5.25