PDA

View Full Version : passing value from array


robertlake
05-21-2009, 01:53 AM
Hello.

I'm trying to replace an input field with a select drop-down list that is derived by the selection from a previous drop-down list. I'm a novice in programming, so this is no small task for me. I have successfully built the dependent drop-down lists using arrays, but I can't get the value of the selection to pass to the next page for Internet Explorer users (it seems to work ok in Firefox).

Links to my test pages in question, if you'd like to see the full code:
http://library.boisestate.edu/faculty/submission-test/author_form-pub.asp
http://library.boisestate.edu/faculty/submission-test/author_confirm-pub.asp

From author_form-pub.asp (the Format field is the only required field, by the way), selecting a College triggers the choices for Department, but the selected Department value does not get passed to author_confirm-pub.asp in IE.

Any assistance here would be greatly appreciated.

Rob

Old Pedant
05-21-2009, 06:03 AM
First of all, this question has nothing whatsoever to do with ASP, per se. It's strictly and HTML/JavaScript question.

The culprit is the way you initialize your group[][] elements.

Because you do:

group[7][11]=new Option("Sociology");

with MSIE, you are essentially doing

group[7][11]=new Option("Sociology", null);

And so then when you later do

temp.options[i]=new Option(group[x][i].text,group[x][i].value)

you are getting null as the ".value" for the option.

Why did you use
group[7][11]=new Option("Sociology");

in the first place??? Why create all these objects that you have no use for???

Just create arrays of strings, instead. Much simpler, much more efficient.

As a minor item: There's really no reason to use both value and text in an <option> when the two are identical.

Example code (only showing two of your "group" arrays):

<FORM name="isc" METHOD="POST" ACTION="author_confirm-pub.asp">

<select id="styled" name="College" onChange="redirect(this.selectedIndex)">
<option value="" SELECTED></option>
<option>College of Applied Technology</option>
<option>College of Arts and Sciences</option>
<option>College of Business and Economics</option>
<option>College of Education</option>
<option>College of Engineering</option>
<option>College of Health Sciences</option>
<option>College of Social Sciences and Public Affairs</option>
<option>Other</option>
</select>
<p>
<select id="styled" name="Department">
<option value="" SELECTED></option>
<option value=" " selected>---Select Department---</option>
</select>

<script>

var group=new Array(groups)
group[0] = ["--Select Department---"];

group[1] = ["---Select Department---","Adult Basic Education","Business and Office Careers",
"Construction Careers","Culinary Arts Careers","Engineering Technology Careers",
"Health and Human Services Careers","Horticulture Careers","Information Technology Careers",
"Manufacturing Careers","Transportation Careers","Workforce Training (Non-Credit Classes)"];

// group[2] through group[5] omitted ...

group[6] = ["--Select Department---","Community and Environmental Health","Master of Health Sciences",
"Nursing","Paramedic Program","Radiologic Sciences","Respiratory Therapy"];

// group[7] omitted ...

function redirect(x)
{
var sel = document.isc.Department;
var curgroup = group[x];
var optnum;
for( optnum = sel.options.length - 1; optnum >= 0; --optnum )
sel.options[ optnum ] = null;
for( optnum = 0; optnum < curgroup.length; ++optnum )
{
var val = curgroup[optnum];
sel.options[optnum] = new Option( val, val );
}
}
</script>
</form>


Untested. Might be a typo here and there. But should be close to right.

By the by: It's bad form to have two objects with the same id. Better to use a class if you are trying to impose a style. But works in current browsers.

robertlake
05-29-2009, 12:30 AM
I didn't have much of a chance to look this over before I left for a vacation. I've returned now and have corrected typos and such to get make your suggestions work for my application. Much, MUCH appreciated! Thank you.