Help, JavaScript
5 отговора
178 прегледа
Help, JavaScript
Kak da napravia Select taka, che kogato izbora na niakoia opcia ne e jelatelen, da mi izbira avtomatichno (prinuditelno) opcia ot syshtia Select chiito index e [gr_index] ? Tova shte e funkcia, koiato shte vikam pri onChange na default opciata na Selecta.
Sigurno e neshto sys... option.selected, ama kak se zapisva tochno, znae li niakoi?
Blagodaria predvaritelno.
Sigurno e neshto sys... option.selected, ama kak se zapisva tochno, znae li niakoi?
Blagodaria predvaritelno.
Re: Help, JavaScript
Дано ти помогнат тези примери
Examples
In the following example, the getSelectedIndex function returns the selected index in the musicType Select object:
function getSelectedIndex() {
return document.musicForm.musicType.selectedIndex}
The previous example assumes that the Select object is similar to the following:
<SELECT NAME="musicType">
<OPTION SELECTED> R&B
<OPTION> Jazz
<OPTION> Blues
<OPTION> New Age
</SELECT>
Examples
In the following example, the restoreDefault function returns the musicType Select object to its default state. The for loop uses the options array to evaluate every option in the Select object. The if statement sets the selected property if defaultSelected is true.
function restoreDefault() {
for (var i = 0; i < document.musicForm.musicType.length; i++) {
if (document.musicForm.musicType.options.defaultSelected == true) {
document.musicForm.musicType.options.selected=true } }}
The previous example assumes that the Select object is similar to the following:
<SELECT NAME="musicType">
<OPTION SELECTED> R&B
<OPTION> Jazz
<OPTION> Blues
<OPTION> New Age
</SELECT>
Examples
In the following example, the getSelectedIndex function returns the selected index in the musicType Select object:
function getSelectedIndex() {
return document.musicForm.musicType.selectedIndex}
The previous example assumes that the Select object is similar to the following:
<SELECT NAME="musicType">
<OPTION SELECTED> R&B
<OPTION> Jazz
<OPTION> Blues
<OPTION> New Age
</SELECT>
Examples
In the following example, the restoreDefault function returns the musicType Select object to its default state. The for loop uses the options array to evaluate every option in the Select object. The if statement sets the selected property if defaultSelected is true.
function restoreDefault() {
for (var i = 0; i < document.musicForm.musicType.length; i++) {
if (document.musicForm.musicType.options.defaultSelected == true) {
document.musicForm.musicType.options.selected=true } }}
The previous example assumes that the Select object is similar to the following:
<SELECT NAME="musicType">
<OPTION SELECTED> R&B
<OPTION> Jazz
<OPTION> Blues
<OPTION> New Age
</SELECT>
Re: Help, JavaScript
function changeSelected(){
var obj = document.formName.selectName;
if (obj.value == 'nejelan') {
for (var j=0;j<=obj.length;j++) {
if (obj[j].value=='kakvoto iskash') {
obj[j].selected = 'true';
break;
}
}
}
}
Re: Help, JavaScript
само да кажа, че на реда, където започва наклонения текст, вероятно липсва едно [ i ]... Ама като е нака направен форума... какво да се прави!
Баба...
__________________
Е какво като имам имен ден?
Да не искате да черпя?
Баба...
__________________
Е какво като имам имен ден?
Да не искате да черпя?
Blagodaria
Pomognahte mi, blagodaria. I poneje se pipkah dosta vreme s tova neshto, pone da vi kaja kak trygna.
var i;
for (var i=0; i < document.formName.selectName.length; i++) {
if (document.formName.selectName.options.value == "moiata si stoinost" {
document.formName.selectName.options.selected = true;
}
}
Blagodaria vi, oshte vednyj, che se otzovahte. Kato go gledam, mi to izglejda estestveno, ama kato triabva da go izmislia, vse ne trygva :-(
Pozdravi :)
var i;
for (var i=0; i < document.formName.selectName.length; i++) {
if (document.formName.selectName.options.value == "moiata si stoinost" {
document.formName.selectName.options.selected = true;
}
}
Blagodaria vi, oshte vednyj, che se otzovahte. Kato go gledam, mi to izglejda estestveno, ama kato triabva da go izmislia, vse ne trygva :-(
Pozdravi :)
Leleeee!
Znachi tam kydeto pisah "options", ima sled nego kvadratni skobi i "i" za broiach, a to mi e napravilo texta italic....tz, tz, tz !