Hi Everyone,
I've make a script to fill a multi-select, and after that you can submit and php will handle de array to 1 variable.
But it seems to be nessecary to select all added multi-select lines before i submit the form.
Can someone help me to solve this problem?
Below you can find the source you can paste in a test2.php document.
Thanks a lot! 🙂
<HTML>
<HEAD><TITLE>test</TITLE><HEAD>
<BODY>
<?
if(is_array($_POST['links']) && !empty($_POST['links'])) {
$linklist = implode(',',$_POST['links']);
}
else {
$linklist = "";
}
echo $linklist.'<br>';
?>
<SCRIPT LANGUAGE='JavaScript'>
<!-- Begin
//documents.theForm.elements['links[]'];
function deleteLink()
{
if ((document.theForm.elements['links[]'].selectedIndex)>=0)
{
document.theForm.elements['links[]'].options[document.theForm.elements['links[]'].selectedIndex]=null;
if (document.theForm.elements['links[]'].options.length==0)
{
document.theForm.delete_button.disabled=true;
}
//document.theForm.add_button.disabled=true;
}
else
{
alert("Select a URL to delete.");
}
}
function addLink()
{
url=document.theForm.insertlink.value;
if (url=="")
{
alert("Type a Link to add!");
return;
}
else
{
var newURL=new Option(url,url,false,false);
document.theForm.elements['links[]'].options[document.theForm.elements['links[]'].options.length]=newURL;
document.theForm.delete_button.disabled=false;
document.theForm.insertlink.value="";
}
if (document.theForm.elements['links[]'].options.length==5)
{
document.theForm.add_button.disabled=true;
}
}
function selectAll(objSelect)
{
if (objSelect && objSelect.multiple)
{
var colOptions = objSelect.options;
for (var i=0; i<colOptions.length; i++)
colOptions[i].selected = true;
}
return true;
}
// End -->
</script>
<form method=post action=test3.php name=theForm enctype='multipart/form-data' onLoad="javascript:selectAll(links[]);">
<table border=0 cellspacing=0 cellpadding=1>
<tr>
<td width=110 valign=top>Links (max 5)</td>
<td>
<input type=text name=insertlink size='46' maxlength=255> <input type=button class="submitbutton" value="Add link" name=add_button onclick="addLink();"><br>
<select multiple="yes" name="links[]" size='40' style="width:316px;height:130px;margin-bottom:1px;">
</select><br>
<input type=button value="Remove link" class="submitbutton" name=delete_button onclick="deleteLink();">
</td>
</tr>
<tr>
<td colspan=2>
<input class="submitbutton" name="mySubmitButton" type=submit value='send'>
</td>
</tr>
</table>
</form>
</BODY>
</HTML>