Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

User Input Driven multiple list boxes... 1

Status
Not open for further replies.

topub

Programmer
Jun 6, 2006
42
US
Hi there,

I got some help from FAQ's, but now I am stuck at with a different problem.... Any help is greatly appreciated.

Design: An ASP page with 4 multi-select List boxes, populated from a database. User selection [OnClick event] in one list-box, dynamically updates the list boxes on the right...

I have a page that does this to some extent, by reloading the page with user input.

But the problem now is, Once the user makes a seleciton in one of the boxes, the page is automatically refreshed to update the other lists. But I want to allow multi-selection for users in each list-box.

One idea that I tried, but failed is

Code:
<SCRIPT language="JavaScript">
  Function CheckUserInput()
  { 
      // ignore if the user tries to make multi-selection         
       // by pressing Shift or Ctrl while clicking
       if !((window.event.keycode = 16) or (window.event.keycode = 17)) 
       {
           document.frm1.submit();
           return true;
       }
  }
</SCRIPT>

<form name="frm1" post="thispage.asp" method="post">
<select name="drug" MULTIPLE SIZE=10 onclick="CheckUserInput()">
       <option value="1">1</option>
       <option value="2">2</option>
       ...
</SELECT>
</form>


Basically, my idea is to submit onCllick, but ignore submit if the user is trying to make multiselect [by pressing Control or Shift key down]. But is not working..!!
Says error at 'onClick="CheckUserInput()"'

This is one of the unsuccessful approaches....

APPROACH 2:

Same above code, but take user input on Double click.
i.e.
Code:
<form name="frm1" post="thispage.asp" method="post">
<select name="drug" MULTIPLE SIZE=10 onDoubleclick="document.frm1.submit(); Return True;">
       <option value="1">1</option>
       <option value="2">2</option>
       ...
</SELECT>
</form>

For some reason, I couldn't get this to work either....

NOTE: the boxes need to be multi-select

Please advise if there is a way out of this or if there is a better approach.

Thanks a lot,
_Uday
 
javascript is case sensitive.

you can't use Function over function
or onclick over onClick

on a side note I think I would go with a different event like an onBlur() or such. That way when you leave the control the page submits and thus reloads the next select given which select controls have been populated as of yet.



____________ signature below ______________
General FAQ faq333-2924
5 steps to asking a question faq333-3811
 
I know you said you used the FAQ but did you check out both of the linked select FAQ's?

It sounds like a mod to the more client driver one would be better for you with the multiple selections

Linked List Boxes without Reloading Page faq333-3656


____________ signature below ______________
General FAQ faq333-2924
5 steps to asking a question faq333-3811
 
thanks Onpnt...
Case sensitive.... Ghaad.!! I should have reliazed it when the Editor did not change color for the keyword "Function"

thanks man....

About your second suggestions... It is possible to do it on client-side, but the list is a huge list and from multiple tables.

thanks alot man... I'll try the onBlur() event...
_ub
 
no problem. Hope it helps.

One thing you may want to check if it is viable to your situation is the onBlur event being browser friendly. I've been working on a intranet with IE only for a few years now so I haven't really kept up on cross browser functionality as much as I should.


____________ signature below ______________
General FAQ faq333-2924
5 steps to asking a question faq333-3811
 
Another option for you is to use AJAX to retrieve the new field options from the database and then use DOM methods to populate the lists so the page does not have to refresh/submit for the boxes to fill.

Relying on client-side code to do this will of course break the script if the client disables javascript but the same is true for your current solution using javascript so...



At my age I still learn something new every day, but I forget two others.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top