/    Sign up×
Community /Pin to ProfileBookmark

form – select field value

I am trying to assign the value of the selected field from my form into a variable called selectedcity. It doesn’t work, what is wrong with my syntax or whatever. I have added the parts of my code that I think are relevant.

Many thanks

Jim

*********** javascript code here ****************

function cityselection(databaseid,programid,suburbcount)
{
var cityindex = document.selectcity.elements[“city”].selectedIndex;
var selectedcity = document.selectcity.elements[“city”].value;
if (cityindex == 0)
{
alert(“Please Enter a Valid Option”);
return;
}
if (suburbcount == 0)
{
document.selectcity.action = “testcity.asp?databaseid=” + databaseid + “&programid=” + programid + “&selectedcity=” + selectedcity + “&suburbindex=None” + “&cityindex=” + cityindex + “&suburbcount=” + suburbcount;
document.selectcity.submit();
}
else
{
document.selectcity.elements[“selectedindex”].value = cityselection-2;
document.selectcity.action = “suburblist.asp?databaseid=” + databaseid + “&programid=” + programid;
document.selectcity.submit();
}
}

*****************form code here ********************

<form name=”selectcity” method=”post”>

<a class=”blueinformation”>Detailed list of<br /><%=statename%><br />Cities and Towns</a><br /><br />
<select class=”information” name=”city” onchange=”cityselection(‘<%=databaseid%>’,'<%=programid%>’,'<%=suburbcount(indexctr)%>’)”><%=cityoption%></select>
<br /><br />

<!–HIDDEN FORM VARS–>

<input type=”hidden” name=”countryindex” value=”<%=areadictionary.item(“countryindex”)%>”></input>
<input type=”hidden” name=”databaseid” value=”<%=databaseid%>”></input>
<input type=”hidden” name=”suburb” value=”<%=allsuburbs%>”></input>
</form>

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@javaNoobieDec 13.2004 — Please post the generated html codes.. from what i can see.. u do not have the [i]option[/i] elements within yr [i]select[/i] element in the form..
<i>
</i>&lt;select class="information" name="city" onchange="cityselection('&lt;%=databaseid%&gt;','&lt;%=programid%&gt;','&lt;%=suburbcount(indexctr)%&gt;')"&gt;[color=red]&lt;option value='someValue'&gt;[/color]&lt;%=cityoption%&gt;&lt;/select&gt;
Copy linkTweet thisAlerts:
@jbernieauthorDec 13.2004 — Thank JavaNoobie. I actually set up a "drop down list" full of values for the select part of my form. It is called cityoption. Populated from a database earlier in the program.

**** code below ***

do until adorecordset.eof

cityoption = cityoption & "<option>" & adorecordset("city-town") & "</option>"

displaycity(indexctr) = adorecordset("city-town")

suburbcount(indexctr) = 0

indexctr = indexctr + 1

call adorecordset.movenext

loop

** end of code ***

This cityoption list is then used in the select statement area of my form. Maybe I am still missing something though as far as the options go as u can see I need some help around javascript.
Copy linkTweet thisAlerts:
@javaNoobieDec 13.2004 — You failed to include the [i]value[/i] attribute in the [i]option[/i] element.
<i>
</i>&lt;select&gt;
&lt;option [color=red]value='1'[/color]&gt;1&lt;/option&gt;
&lt;option [color=red]value='2'[/color]&gt;2&lt;/option&gt;
&lt;/select&gt;
Copy linkTweet thisAlerts:
@jbernieauthorDec 13.2004 — How do I add the value attribute in as I assign a value from the database field into "cityoption" which includes the "option" attribute?

In the "select" statement, it effectively is a whole list of "options" that have been set up earlier.

In my javascript, I get the correct value of the "selectedIndex" so it is reading the lis of "options" okay from "cityoption".

An example of what I am doing is at www.timeaway.com.au and then select NT to give you the drop down box that appears in my "select" statement".

Thanks
Copy linkTweet thisAlerts:
@javaNoobieDec 13.2004 — var selectedcity = document.selectcity.elements["city"][color=red].value[/color]
You will need to include the value attribute in the option element. If you do not, i believe it returns a [i]null[/i] value.

<i>
</i>dim n 'counter variable
n = 0
do until ...
n = n + 1
cityoption = cityoption &amp; "&lt;option value='" &amp; n &amp; "'&gt;" &amp; adorecordset("city-town") &amp; "&lt;/option&gt;"
:
:
loop
Copy linkTweet thisAlerts:
@jbernieauthorDec 14.2004 — ? Many thanks for your help. Got it now.
×

Success!

Help @jbernie spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...