PDA

View Full Version : javascript firefox problems


tawanda
08-02-2005, 02:38 PM
:thumbdn:

I had issues earlier with dynamic drop down lists, and they are now fixed for IE, however when I run the page in firefox, the second of the two lists (whose value is determined in javascript) always displays undefined instead of thier value. It works on IE??? any ideas??

the code looks something like....

<script language = "javascript">
var arrClasses, arrALH, arrCOM, arrECO, arrPSY,
arrALH = ["1111014", "2263041", "2451041"]
arrCOM = ["1053041", "1211041"]
arrECO = ["1013041"]
arrPSY = ["1013041", "1032041"]
arrClasses = [arrALH, arrCOM, arrECO, arrPSY]


function handleChange(newDisplay)
{
var deptSelect, numSelect, numEntries, i
deptSelect = document.shortForm.primary
numSelect = document.shortForm.secondary


for(i = numSelect.length; i >0; i--)
{
numSelect.options[i-1] = null
}

numSelect.options[0] = new Option ("--Select--", 0)

if(newDisplay>=0)
{
numEntries = arrClasses[newDisplay].length

for(i =1; i<= numEntries; i++)
{
numSelect.options[i] = new Option((arrClasses[newDisplay]) [i-1], (arrClasses[i-1[i]]))
}

}

numSelect.selectedIndex = 0
}

</script>

and the html...

<form action="sendmail.asp" method="post" name="shortForm">
<select name="primary" onChange="handleChange(this[this.selectedIndex].value)">
<option value = "-1" selected>--Select--</option>
<option value = "0">ALH</option>
<option value = "1">COM</option>
<option value = "2">ECO</option>
<option value = "3">EDU</option>
<option value = "4">ENG</option>
<option value = "5">HIS</option>
<option value = "6">MAT</option>
<option value = "7">NUR</option>
<option value = "8">PSY</option>
<option value = "9">SPE</option>
<option value = "10">CTD</option>
</select>
</td>
<td colspan="2"><select name="secondary">
<option value ="-1"> -- Select --</option>
<option></option>
<option></option>
</select></td>

</form>

Any help appriciated
Thanks!

RysChwith
08-02-2005, 04:24 PM
It's because you're referencing the forms in an IE proprietary syntax. Change "document.shortForm.primary" to "document.forms[0][0]" and "document.shortForm.secondary" to "document.forms[0][1]" and you should be okay.

Rys

Jon Hanlon
08-02-2005, 09:06 PM
It's not IE proprietary syntax at all. The forms collection dates back to Netscape 3.
Try "document.forms.shortForm.primary" if it's not referencing the form properly.

Whack some alerts in like
alert( typeof(numSelect))
to see what happens. You should see "object".

tawanda
08-03-2005, 10:12 AM
Thank you all for your help. I tried Rys's adivce and the javascript stopped working. So then I tried Mr. Hanlon's advice and it started to work again, but firefox still has the same issues.

I am using ASP to write the form processing information. I am using

Resposnse.Write() to see my results and when I run it in IE they look like
ALH1120304

and in firefox they look like

ALHundefined.

The code I am using is the same as posted previously except for the 'document.forms.shortform.primary' change...

I'll post the ASP incase something is wrong there

Dim primary
Dim secondary

primary = findValue(Trim(Request.Form("primary")))
secondary = Trim(Request.Form("secondary"))

function findValue(initValue)
if (initValue = "0") then
findValue = "ALH"
elseif (initValue = "1") then
findValue = "COM"
elseif (initValue = "2") then
findValue = "ECO"
endif
end function

Dim BodyBB

BodyBB = BodyBB & "First Course Requested " & primary & secondary & "<br>"& VbCrLf

Dim mail
Set mail = Server.CreateObject("CDO.Message")
mail.To = "&Request.Form('emailTo')&"
mail.From = "&Request.Form('emailFrom')&"
mail.Subject = Subject
mail.TextBody = BodyBB
mail.Send

'Response.Redirect("ok.htm")
Response.Write(BodyBB)

do not know if this is where the problem is????

thanks again
tawanda

tawanda
08-05-2005, 12:45 PM
could the problem be in this one line

numSelect.options[i] = new Option((arrClasses[newDisplay]) [i-1], (arrClasses[i-1[i]]))

??

is the syntax correct???