| View previous topic :: View next topic |
| Author |
Message |
gialby
Joined: 10 May 2006
Posts: 4
|
| Posted: Wed May 10, 2006 5:58 am CreateElement("SELECT") and check value select |
|
|
i have a web form where a select is created client side by in dhtml from vbscript function:
function creascuola(caso)
vettore=ARRAY("SELEZIONARE SCUOLA","CERVI","FOSCOLO","GAROFANI","MONTE AMIATA","MILANO","MINCIO","ORCHIDEE")
if caso=1 then
scuole.innerHTML=""
Set label = document.CreateElement("label")
label.innerHTML="<strong><font color=#FFFFFF>SCUOLE:</font></strong>"
Set objSelect = document.CreateElement("SELECT")
objSelect.name="scuola"
for i=0 to 7
Set objOption = document.CreateElement("option")
objOption.text=vettore(i)
objOption.value=i
objSelect.options.add(objOption)
next
scuole.appendChild(label)
scuole.appendChild(objSelect)
else
scuole.innerHTML=""
end if
end function
The script create a select without problem. After this when the user submit the form start a check function of the selected value. But i have problem to check the value of the select created by dhtml.
if document.getElementByName("scuola").value=0 then
msgbox "ERRORE"
exit sub
end if
The browser send me a error "Property not supported from the object 'document.getElementByName'".
I don't know where is the error.
Please somebody help me!
Gianluca[/b] |
|
|
kanenas
Joined: 14 Dec 2004
Posts: 193
|
| Posted: Wed May 10, 2006 3:58 pm Wrong function name |
|
|
The function is named "getElementsByName" (note "Elements" is plural) and it returns a collection of nodes. Change the code to:
Code: document.getElementsByName("scuola")[0].value
Anytime you get an error message like "property not supported", you've probably got a typo resulting in an undefined value. Try to fetch a property of "undefined" and voila--"property not supported".
Note that by using VBScript, your page will only work properly in IE. I strongly urge you to use Javascript. |
|
|
gialby
Joined: 10 May 2006
Posts: 4
|
| Posted: Wed May 10, 2006 10:05 pm |
|
|
thanks...
but i try without solution
i try
document.getElementsByName("scuola")[0].value
and
document.getElementsByName("scuola").value=0
and
document.form.scuola.value=0
the select is create but i can't get value form it...
The error is always property is not support
Maybe i need to check value of the dynamic select in different way?
Gianluca |
|
|
gialby
Joined: 10 May 2006
Posts: 4
|
| Posted: Wed May 10, 2006 10:37 pm |
|
|
i solve problem. i used the id property.
function creascuola(caso)
vettore=ARRAY("SELECT","CERVI","FOSCOLO","GAROFANI","MONTE AMIATA","MILANO","MINCIO","ORCHIDEE")
if caso=1 then
scuole.innerHTML=""
Set label = document.CreateElement("label")
label.innerHTML="<strong><font color=#FFFFFF>SCUOLE:</font></strong>"
Set objSelect = document.CreateElement("SELECT")
objSelect.name="scuola"
objSelect.id="sc"
for i=0 to 7
Set objOption = document.CreateElement("option")
objOption.text=vettore(i)
objOption.value=i
objSelect.options.add(objOption)
next
scuole.appendChild(label)
scuole.appendChild(objSelect)
else
scuole.innerHTML=""
end if
end function
check function
if document.getElementById("sc").value=0 then
msgbox "errore"
document.getElementById("sc").focus()
exit sub
end if
i don't know by name i can't get value but by id i have not problem.
thanks
Gianluca |
|
|
tuonghd
Joined: 14 Mar 2007
Posts: 1
|
| Posted: Wed Mar 14, 2007 2:08 am |
|
|
gialby wrote: i solve problem. i used the id property.
function creascuola(caso)
vettore=ARRAY("SELECT","CERVI","FOSCOLO","GAROFANI","MONTE AMIATA","MILANO","MINCIO","ORCHIDEE")
if caso=1 then
scuole.innerHTML=""
Set label = document.CreateElement("label")
label.innerHTML="<strong><font color=#FFFFFF>SCUOLE:</font></strong>"
Set objSelect = document.CreateElement("SELECT")
objSelect.name="scuola"
objSelect.id="sc"
for i=0 to 7
Set objOption = document.CreateElement("option")
objOption.text=vettore(i)
objOption.value=i
objSelect.options.add(objOption)
next
scuole.appendChild(label)
scuole.appendChild(objSelect)
else
scuole.innerHTML=""
end if
end function
check function
if document.getElementById("sc").value=0 then
msgbox "errore"
document.getElementById("sc").focus()
exit sub
end if
i don't know by name i can't get value but by id i have not problem.
thanks
Gianluca
Replace : vettore=ARRAY("SELECT","CERVI","FOSCOLO","GAROFANI","MONTE AMIATA","MILANO","MINCIO","ORCHIDEE")
-->vettore=Array("SELECT","CERVI","FOSCOLO","GAROFANI","MONTE AMIATA","MILANO","MINCIO","ORCHIDEE")
objOption.text=vettore(i)
-->objOption.text=vettore[i]. |
|
|
| |
|
|
|