Connected Comboxes

Discussion in 'JavaScript' started by levani, Aug 14, 2009.

  1. #1
    Hi,

    I use this javascript to create connected dropdown boxes on my website, but I have some problems. Look at the demonstration: http://javascript.internet.com/navigation/connected-comboxes.html (The code is below)

    as you see the first box starts with [ Type ] and the second [ style ]. I need to make them disabled somehow (or remove at all) to prevent its selection. I compare the data from the boxes with an empty value to prevent form submission if one of the two boxes is empty and when this [ Type ] or [ style ] is selected it thinks that the selection has been made. How can I solve this problem?

    Thanks
     
    levani, Aug 14, 2009 IP
  2. NoamBarz

    NoamBarz Active Member

    Messages:
    242
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    58
    #2
    If I understood you correctly, you wan't the form to be disabled as long as the two boxes aren't filled out?

    Try something like this:

    <form name='frm' method='post' action='javascript:checkform();'>

    when the form submits, it goes to the checkform function. That function checks that the dropdowns aren't empty. If one of the boxes isn't filled, return false.

    function checkform(){
    var e = document.getElementBYId('box1');
    if(e.value =="" || e.value == '-1') return false;

    e = document.getElementBYId('box2');
    if(e.value =="" || e.value == '-1') return false;

    document.frm.action = 'target.html';
    document.frm.submit();
    }


    I hope this helps
     
    NoamBarz, Aug 14, 2009 IP