and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I've got a select list with 227 options. I want to eliminate the options that don't have documents associated with them. To do this I tagged the values of the options I want with 'HAS_DOCS'. I'll post the meat of the code and carve out the bulk of the 227 entries. The list is shortened when the 'Documents' radio button is clicked.
The problem is that it takes 5 clicks to get through the list. It's skipping some entries - always the same ones, but they're no different than the rest (I think). Does anyone see anything obvious in this code that would make the javascript not process the entire for loop?
Thanks.
Bob
[syntax="html"]
<head>
<script type="text/javascript">
function shrink_list() {
var form_len = document.forms['DOCGRPform'].DOCGRP_ID.options.length;
for (index = 0; index < form_len; index++) {
var curval = document.forms['DOCGRPform'].DOCGRP_ID.options[index].value;
if (curval.match("HAS_DOCS") == null) {
document.forms['DOCGRPform'].DOCGRP_ID.options[index] = null;
}
}
document.DOCGRPform.DOCGRP_ID.focus();
}
</script>
</head>
<table>
<tr>
<td valign="top">
<br>
<strong>Choose a Group to analyze</strong><br>
<form name="DOCGRPform"action="my_prog.php" method="POST">
<select name="DOCGRP_ID" >
<option value="4" >Public Site(4)</option>
<option value="5" >Secure Site(5)</option>
<option value="7" >Root(7)</option>
<option value="232HAS_DOCS" >Core 1*(232)</option>
<option value="231" >Reports(231)</option>
<option value="731HAS_DOCS" >Consortium*(731)</option>
<option value="2548HAS_DOCS" >EXPORT*(2548)</option>
</select>
</td>
<td><br><b>Display Choice</b><br>
<input type="radio" name="doc_or_user" value="Documents" onclick="shrink_list();"> Documents
<input type="radio" name="doc_or_user" checked="checked" value="Users"> Users (default)<br>
<input type="hidden" name="Context" value="Analyze">
<input name="submit" type="submit" value="Analyze This">
</td>
</form>
</tr>
</table>
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Last edited by rlg0613 on Wed Sep 26, 2007 6:31 pm, edited 1 time in total.
Hmm, not sure. You are declaring index, then not using it anywhere except in the for loop, which has it's own instance of an index variable. Get rid of that declaration.
Why not trim it server-side? You obviously can tell which items you want to display when generating the data server-side, so why not simply not create the elements that don't have documents?
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
I tried to clean up the snippet when I pulled it from the actual app. That 'index' declaration was no longer there.
I actually use both the full select list and the shortened one I'm trying to create. That's why there are 2 radio buttons. One for the full list 'User' and one for the short list 'Documents'. Point well taken though - I could generate 2 select lists in separate divs and toggle between them...
I'd still like to know why it doesn't work. It seems so simple.