简体   繁体   English

具有JavaScript操作的列表框未发布值

[英]Listbox with javascript action not posting values

I have the following form: 我有以下表格:

<form name='progObj_form' method='POST' enctype='multipart/form-data' action='processpage.php'>
<select name='manageObj[]' id='objectives'  multiple="multiple">
<option value=0>there are no objectives for this program</option>
</select><br />
<a href='#nogo' onclick="delItem(objectives,0,'objEditBtn')" class='shiftOpt'>delete selected</a><br />
<input name='newObjective' type='text' id='newObjective'/>
<input name='addNew' type='button' onclick="AddItem(newObjective.value,6,'objectives','objEditBtn');" value='add objective'/>
<input name="passProgID" type="hidden" value="1" /><br />
<input name="objectiveEdit" id="objEditBtn" type="submit" value="save changes" disabled=disabled/>
</form>

that allows data (objectives in this case) to be added and deleted from a list box. 允许在列表框中添加和删除数据(在这种情况下为目标)。 That all works well but for some reason the updated listbox values aren't being passed to the process page. 一切正常,但由于某种原因,更新后的列表框值未传递到流程页面。

I'm catching the data like so (simplified): 我正在捕获这样的数据(简化):

if (isset($_POST['objectiveEdit'])){
$progID=$_POST['passProgID'];
 for ($v=1;$v<count($_POST['manageObj']);$v++){
   $value=$_POST['manageObj'][$v];
   $sqlObj="INSERT INTO progObjective (progID,objective,objectiveOrder) VALUES ($progID,$value,$v)";
   $result = mssql_query($sqlObj,$linkProbation) or die('Query failed: '.$sqlObj);  
 }//end for ($a=0;$a<count($_POST['manageObj']);$a++)   
$objMsg=print_r($_POST['manageObj']).$sqlObj;       
}//end if (isset($_POST['objectiveEdit'])

For $objMsg , I get a response of 1 and the array doesn't print because ostensibly, it's empty which means that it also doesn't enter the for loop. 对于$objMsg ,我得到一个1的响应,并且该数组不打印,因为表面上它是空的,这意味着它也没有进入for循环。

I can include the javascript as well but started with just this for simplicity since I'm probably just overlooking something obvious?! 我也可以包括javascript,但是为了简单起见,仅以此开头,因为我可能只是忽略了一些明显的东西?!

Option elements are never sent to the server. 选项元素永远不会发送到服务器。 Only the value of the selected option will be sent. 仅发送所选选项的value

In your case, something like manageObj=x will be sent to the server, where x is the value of the option element that is selected by the user. 在您的情况下,诸如manageObj=x将发送到服务器,其中x是用户选择的option元素的value It is possible that you misunderstand the [] when it's used in a name attribute. name属性中使用[]时,您可能会误解。

You should try to find a different method if you want to send the objectives created by the user to the server. 如果要将用户创建的目标发送到服务器,则应尝试找到其他方法。 You could store the data in hidden input s for example. 例如,您可以将数据存储在隐藏的input s中。

So I finally figured it out! 所以我终于想通了! There's no array because there are no selections made! 没有数组,因为没有选择! I updated the submit button to call a SELECT ALL function and now it's all good. 我更新了提交按钮以调用SELECT ALL函数,现在一切正常。

 <input name="objectiveEdit" id="objEditBtn" type="submit" value="save changes" onclick="selectAll('objectives',true)" />

name =' manageObj [] '-不应该是name =' manageObj '吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM