Home > Web Front-end > JS Tutorial > body text

A little experience in operating the select drop-down list box with javascript_form special effects

WBOY
Release: 2016-05-16 18:31:55
Original
1007 people have browsed it

According to my usual web development style, all events that do not directly operate the database are implemented by JavaScript as much as possible, so I plan to use js to complete this requirement.
First, let’s analyze the specific situation: This page is an update page. The brand has two fields: brand 1 and brand 2. Brand 2 can be empty, but brand 1 cannot be empty, so the drop-down list box of brand 2 is smaller than that of brand 1. One more item; if any of the first 8 images of the brand is selected, the "active status" should be hidden, otherwise the default display status of "active status" is "potential"; when the query results of brand 1 and brand 2 have any one In the first 8 photos of the brand, the "active status" must also be hidden, otherwise the default display status of "active status" is "potential".
Part of the page content

Copy code The code is as follows:


javascript code
Copy code The code is as follows:

function changebrand1(oTextbox)
{
var brandTag=document.getElementById("ddlistSecondConsumeBrand");
var brand1=document.getElementById("txtbrand1");
var brand2=document.getElementById("txtbrand2");
var brandcolls=brandTag.options;
var textvalue=oTextbox.value;
var flag=0;
if(textvalue.length==0)
{
flag=1;
}
else if(textvalue.length>0)
{
for(var i=0;i{
if(oTextbox==brand1 && brandcolls[i].text==textvalue)
{
document.getElementById("ddlistFirstConsumeBrand").options.selectedIndex=i-1;
flag=1;
ChangeBrand(document.getElementById("ddlistFirstConsumeBrand"));
}
else if(oTextbox==brand2 && brandcolls[i].text==textvalue)
{
brandTag.selectedIndex=i;
flag=1;
ChangeBrand(brandTag);
}
}

if(flag==0)
{
alert("输入品牌错误!");
oTextbox.value="";
oTextbox.focus();
}
}
}

function ChangeBrand(me){
var brand1ID = document.all.ddlistFirstConsumeBrand.value;
var brand2ID = document.all.ddlistSecondConsumeBrand.value;
var brandvalue1=document.getElementById("txtbrand1");
var brandvalue2=document.getElementById("txtbrand2");
if((brand1ID=="10")&&(brand2ID=="-1"))
{
document.all.ddlistMilkPeriod.value=9;
}

for(var i=0;i{
if(document.getElementById("ddlistFirstConsumeBrand") == me && document.all.ddlistFirstConsumeBrand.selectedIndex==i)
{
brandvalue1.value=document.getElementById("ddlistFirstConsumeBrand").options[i].text;
}
if(document.getElementById("ddlistSecondConsumeBrand") == me && document.all.ddlistSecondConsumeBrand.selectedIndex==i)
{
brandvalue2.value=document.getElementById("ddlistSecondConsumeBrand").options[i].text;
}

if(i<8 && document.getElementById("ddlistFirstConsumeBrand") == me && document.all.ddlistFirstConsumeBrand.selectedIndex==i)
{
document.all.dv1.style.display="block";
document.all.dv2.style.display="none";
document.all.dv3.style.display="none";
document.getElementById("ddlistPotential").options[0].selected="selected";
break;
}
else if(i>0 && i<9 && document.getElementById("ddlistSecondConsumeBrand") == me && document.all.ddlistSecondConsumeBrand.selectedIndex==i)
{
document.all.dv1.style.display="block";
document.all.dv2.style.display="none";
document.all.dv3.style.display="none";
document.getElementById("ddlistPotential").options[0].selected="selected";
break;
}
else if(i>8)
{
document.all.dv1.style.display="none";
document.all.dv2.style.display="block";
document.all.dv3.style.display="block";
document.getElementById("ddlistPotential").options[1].selected="selected";
}
}
}
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template