search
HomeBackend DevelopmentPHP Tutorial移动到右边的,为什么要选中后提交才能获取到相应的值。

本帖最后由 qq914260102 于 2013-10-14 16:02:07 编辑

如果选到右边,是无法获取到值的,必须要点击一次,选中了才能获取到,怎么让右边的默认能获取值








> " onclick="move(this.form.list1,this.form.list2)" name="B1">




sortitems = 1;  // Automatically sort items within lists? (1 or 0)function move(fbox,tbox) {for(var i=0; i<fbox.options.length; i++) {if(fbox.options[i].selected && fbox.options[i].value != "") {var no = new Option();no.value = fbox.options[i].value;no.text = fbox.options[i].text;tbox.options[tbox.options.length] = no;fbox.options[i].value = "";fbox.options[i].text = "";}}BumpUp(fbox);if (sortitems) SortD(tbox);}function BumpUp(box)  {for(var i=0; i<box.options.length; i++) {if(box.options[i].value == "")  {for(var j=i; j<box.options.length-1; j++)  {box.options[j].value = box.options[j+1].value;box.options[j].text = box.options[j+1].text;}var ln = i;break;   }}if(ln < box.options.length)  {box.options.length -= 1;BumpUp(box);   }}function SortD(box)  {var temp_opts = new Array();var temp = new Object();for(var i=0; i<box.options.length; i++)  {temp_opts[i] = box.options[i];}for(var x=0; x<temp_opts.length-1; x++)  {for(var y=(x+1); y<temp_opts.length; y++)  {if(temp_opts[x].text > temp_opts[y].text)  {temp = temp_opts[x].text;temp_opts[x].text = temp_opts[y].text;temp_opts[y].text = temp;temp = temp_opts[x].value;temp_opts[x].value = temp_opts[y].value;temp_opts[y].value = temp;      }   }}for(var i=0; i<box.options.length; i++)  {box.options[i].value = temp_opts[i].value;box.options[i].text = temp_opts[i].text;   }}

回复讨论(解决方案)

懒得看代码理解,纯想象
form提交,select只提交选择的option
所以如果要提交list2,要把全部都加设selected属性,或者把option的每个value都赋值一个新控件(例如hidden)来提交

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
PHP Performance Tuning for High Traffic WebsitesPHP Performance Tuning for High Traffic WebsitesMay 14, 2025 am 12:13 AM

ThesecrettokeepingaPHP-poweredwebsiterunningsmoothlyunderheavyloadinvolvesseveralkeystrategies:1)ImplementopcodecachingwithOPcachetoreducescriptexecutiontime,2)UsedatabasequerycachingwithRedistolessendatabaseload,3)LeverageCDNslikeCloudflareforservin

Dependency Injection in PHP: Code Examples for BeginnersDependency Injection in PHP: Code Examples for BeginnersMay 14, 2025 am 12:08 AM

You should care about DependencyInjection(DI) because it makes your code clearer and easier to maintain. 1) DI makes it more modular by decoupling classes, 2) improves the convenience of testing and code flexibility, 3) Use DI containers to manage complex dependencies, but pay attention to performance impact and circular dependencies, 4) The best practice is to rely on abstract interfaces to achieve loose coupling.

PHP Performance: is it possible to optimize the application?PHP Performance: is it possible to optimize the application?May 14, 2025 am 12:04 AM

Yes,optimizingaPHPapplicationispossibleandessential.1)ImplementcachingusingAPCutoreducedatabaseload.2)Optimizedatabaseswithindexing,efficientqueries,andconnectionpooling.3)Enhancecodewithbuilt-infunctions,avoidingglobalvariables,andusingopcodecaching

PHP Performance Optimization: The Ultimate GuidePHP Performance Optimization: The Ultimate GuideMay 14, 2025 am 12:02 AM

ThekeystrategiestosignificantlyboostPHPapplicationperformanceare:1)UseopcodecachinglikeOPcachetoreduceexecutiontime,2)Optimizedatabaseinteractionswithpreparedstatementsandproperindexing,3)ConfigurewebserverslikeNginxwithPHP-FPMforbetterperformance,4)

PHP Dependency Injection Container: A Quick StartPHP Dependency Injection Container: A Quick StartMay 13, 2025 am 12:11 AM

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Dependency Injection vs. Service Locator in PHPDependency Injection vs. Service Locator in PHPMay 13, 2025 am 12:10 AM

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHP performance optimization strategies.PHP performance optimization strategies.May 13, 2025 am 12:06 AM

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHP Email Validation: Ensuring Emails Are Sent CorrectlyPHP Email Validation: Ensuring Emails Are Sent CorrectlyMay 13, 2025 am 12:06 AM

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.