PDA

View Full Version : Array and selected dropdowns



cabbagecoder
19 Oct 2005, 09:37 AM
hi

Hoping someone can help with this code, I'm looking for the array to check against the specified country "countrycheck" if its the same, then the dropdown is set as selected for that country.
The reason for this, is that the countrycheck will be pulled from a database.

Anyway, I cant get it to work - can anybody help?? Thanks :)


<%@LANGUAGE="JAVASCRIPT" CODEPAGE="1252"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<%
var countryarray = new Array("BE","DE","DK","ES","FI","FR","ITL","NL","NO","SE","UK","ZA")
var assigneeshow
var myfront
var mymiddle
var myend
countrycheck = 0;
countrycheck = "UK"

myfront = "<OPTION value="
mymiddle = "SELECTED>"
myend = "</OPTION>"
%>
<SELECT name="Country">
<%

for(i=0; i<countryarray.length; i++)
{
if (countrycheck == countryarray[i])
{
document.write (myfront & countryarray[i] & mymiddle & countryarray[i] & myend)
}
else
{
document.write (myfront & countryarray[i] & ">" & countryarray[i] & myend)
}
}

%>
</SELECT>
</body>
</html>

DanInManchester
01 Jan 2006, 10:54 AM
It looks like your missing a space so the browser wont be parsing it correctly


try mymiddle = " SELECTED>"

also if you're going to be strict about the syntax use it like this

<option value="UK" selected="selected">