/    Sign up×
Community /Pin to ProfileBookmark

How can I add to hyperlink to this?

Below is a javascript that has two boxes…one with values that the user can select to go into a ‘selected’ box. If I wanted to add a value to the ‘selected’ box using a hyperlink…how could I do this?

In other words…lets say I wanted to give the user the option of Clicking on a hyperlink….the hyperlink would add a group of values to the selected box.

[code=php]
<script language=”JavaScript”>
function move(fbox, tbox) {
var arrFbox = new Array();
var arrTbox = new Array();
var arrLookup = new Array();
var i;
for(i=0; i<tbox.options.length; i++) {
arrLookup[tbox.options[i].text] = tbox.options[i].value;
arrTbox[i] = tbox.options[i].text;
}
var fLength = 0;
var tLength = arrTbox.length
for(i=0; i<fbox.options.length; i++) {
arrLookup[fbox.options[i].text] = fbox.options[i].value;
if(fbox.options[i].selected && fbox.options[i].value != “”) {
arrTbox[tLength] = fbox.options[i].text;
tLength++;
} else {
arrFbox[fLength] = fbox.options[i].text;
fLength++;
}
}
arrFbox.sort();
arrTbox.sort();
fbox.length = 0;
tbox.length = 0;
var c;
for(c=0; c<arrFbox.length; c++) {
var no = new Option();
no.value = arrLookup[arrFbox[c]];
no.text = arrFbox[c];
fbox[c] = no;
}
for(c=0; c<arrTbox.length; c++) {
var no = new Option();
no.value = arrLookup[arrTbox[c]];
no.text = arrTbox[c];
tbox[c] = no;
}
}
function selectAll(box) {
for(var i=0; i<box.length; i++) {
box.options[i].selected = true;
}
}
</script>
</head>

<body>
<table width=”100%” border=”0″>
<tr valign=”top”>
<td>
<form action=”maincode.php” method=”post” name=”combo_box”>
<p>
<center>

<table width=”38%”>
<tr>

<td>
<table width=”100%” border=”0″>
<tr>
<td valign=”top”> <table width=”100%” border=”0″>
<tr>
<td><table width=”100%” border=”0″>
<tr>
<td width=”50%”><div align=”center”><font color=”#FF9900″ face=”Arial, Helvetica,
sans-serif”><strong>Town</strong></font></div></td>
<td><div align=”center”><font color=”#FF9900″ face=”Arial, Helvetica,
sans-serif”><strong>Selected
Towns</strong></font></div></td>
</tr>
<tr>
<td><div align=”center”>
<select name=”list1[]” size=”6″ multiple class=”remarks” style=”width:150″>
Town1
town2
town3
town4
</select>
</div></td>
<td><div align=”center”>
<select multiple size=”6″ class=”remarks” name=”selecttown[]” style=”width:150″>
</select>
</div></td>
</tr>
<tr>
<td><div align=”center”>
<input name=”button” class=”remarks” type=”button”
onClick=”move(this.form.elements[‘list1[]’],this.form.elements[‘selecttown[]’])” value=”Add Selected &gt;&gt;”>
</div></td>
<td><div align=”center”>
<input name=”button2″ class=”remarks” type=”button”
onClick=”move(this.form.elements[‘selecttown[]’],this.form.elements[‘list1[]’])” value=”&lt;&lt; Remove Selected”>
</div></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
<tr>
<td valign=”top”><hr color=”#0000CC”></td>
</tr>
<tr>
<td valign=”top”><div align=”center”><font color=”#FF9900″ face=”Arial, Helvetica,
sans-serif”><strong>Price
Range:</strong></font></div></td>
</tr>
</table></td>
</tr>
<tr>
<td valign=”top”><hr color=”#0000CC”></td>
</tr>
<tr>
<td valign=”top”><div align=”center”>
<input type=”submit” name=”submit_button” value=”Search Now” onClick=”selectAll(document.combo_box.elements[‘selecttown[]’]);”>
</div></td>
</tr>
</table></td>
</tr>
</table>
</center>
</form></td>
<td width=”100%”>
Greater Claremont

</td>
</tr>
</table>
<p>&nbsp;</p>

<p>
<?
if(isset($_POST[“list2”])) {
echo “values selected:<br>”;
while(list($key,$val)=each($_POST[“list2”])) {
echo $val;
echo “<br>”;
}
}
?>
<?
include(“../includes/footer.php”);
?>
</body>
</html>

[/code]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@neil9999Sep 20.2003 — Have a look at [URL]http://javascript.internet.com/forms/form-swapper-2.html[/URL] .

Neil
×

Success!

Help @sgtpepper 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 4.29,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

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