ScrabbleKing
Programmer
How do I get nowSel and prevSel to swap each time the 'Swap' button is pressed (and only if both nowSel and prevSel have values)?
Code:
<script type="text/javascript">
var selected=false;
function showSel(s){
var t1=s.form['prevSel'];
var t2=s.form['nowSel'];
selected?t1.value=selected:null;
selected=s.options[s.selectedIndex].text;
t2.value=selected;
}
</script>
<body>
<form>
Previous selected<input type="text" readonly="readonly" name="prevSel">
<br>
<br>
<select id="selSeaShells" onchange="showSel(this)">
<option value="val0">sea zero</option>
<option value="val1">sea one</option>
<option value="val2">sea two</option>
<option value="val3">sea three</option>
<option value="val4">sea four</option>
</select>
<br>
<br>
Now selected<input type="text" readonly="readonly" name="nowSel">
<br>
<br>
<INPUT TYPE="button" VALUE="Swap" onclick="swapSel();">
</form>
</body>