SitePoint Sponsor

User Tag List

Results 1 to 20 of 20
  1. #1
    Non-Member
    Join Date
    Aug 2007
    Posts
    494
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Select combobox Region ==> City

    Select combobox Region ==> City

    Hi everyone.

    My page htm this:

    Code:
    <html>
    
    <head>
    
    <script language="javascript">
    
    <!--
    
    var regiondb = new Object()
    regiondb["Assente"] = [{value:"Ferie", text:"Ferie"},
                          {value:"Festivit&#224; abolita", text:"Festivit&#224; abolita"},
                          {value:"Malattia", text:"Malattia"},
                          {value:"Infortunio", text:"Infortunio"},
                          {value:"Riposo Fisiologico", text:"Riposo Fisiologico"},
                          {value:"Riposo Compensativo", text:"Riposo"},
                          {value:"Permesso retribuito", text:"Permesso"},
                          {value:"Permesso Sind./ARCA", text:"Permesso Sind"},
                          {value:"Ricovero Ospedaliero", text:"Ricovero"},
                          {value:"Part-time", text:"Part-time"},
                          {value:"Assemblea Sindacale", text:"Assemblea"},
                          {value:"Sciopero", text:"Sciopero"},
                          {value:"Aspettativa", text:"Aspettativa"},
                          {value:"Carica Pubblica", text:"Carica Pubblica"},
                          {value:"Da giustificare", text:"Da giustificare"}];
                          
    regiondb["PresenteA"] = [{value:"Fuori sede", text:"Fuori sede"},
                            {value:"In sede", text:"In sede"}];
                            
    regiondb["PresenteB"] = [{value:"Monoperatore", text:"Monoperatore"},
                            {value:"Coppia", text:"Coppia"},
                            {value:"Formazione a tre", text:"Formazione a tre"},
                            {value:"Appoggio", text:"Appoggio"},
                            {value:"Fuori sede", text:"Fuori sede"},
                            {value:"In sede", text:"In sede"}];
     
     
    function setCities(chooser) 
    
    {
        var newElem;
        var where = (navigator.appName == "Microsoft Internet Explorer") ? -1 : null;
        var cityChooser = chooser.form.elements["tipo_stato_giornaliero"];
        while (cityChooser.options.length)
        
     {
            cityChooser.remove(0);
        }
        
        var choice = chooser.options[chooser.selectedIndex].value;
        var db = regiondb[choice+regionVar]; // regionVar is A or B
    
        newElem = document.createElement("option");
        newElem.text = "Seleziona valore";
        newElem.value = "";
        cityChooser.add(newElem, where);
        if (choice != "") 
        
        {
            for (var i = 0; i < db.length; i++) 
            
            {
                newElem = document.createElement("option");
                newElem.text = db[ i ].text;
                newElem.value = db[ i ].value;
                cityChooser.add(newElem, where);
            }
        }
    
    } 
       
        // -->
        
    </script>
    
    </head>
    
    <body>
    
    <form method="POST" action="page.asp">
    
    <select size="8" name="D1" multiple onChange="window.document.location='select.htm?var='+this.options[this.selectedIndex].value+'';">
    	<option>Select</option>
    	<option value="A-DVD">DVD</option>
    	<option value="A-DVDR">DVDR</option>
    	<option value="B-CDR">CDR</option>
    	<option value="B-CD">CD</option>
    </select>
    	
    
    <select name="stato_dipendente" onchange="setCities(this)">
    	<option>Seleziona stato giornaliero</option>
    	<option value="Assente">Assente</option>
    	<option value="Presente">Presente</option>
    </select></td>
    
    <select name="tipo_stato_giornaliero" onchange="onChangeStatus(this);">
    	<option>Seleziona tipo stato giornaliero</option>
    </select>
    	
    </form>
    
    </body>
    
    </html>
    1) The variable is A when in select D1 is selected value DVD or value DVDR .

    2) The variable is B when in select D1 is selected value CDR or value CD .

    Code:
    <select size="8" name="D1" multiple>
        <option>Select</option>
        <option value="A-DVD">DVD</option>
        <option value="A-DVDR">DVDR</option>
        <option value="B-CDR">CDR</option>
        <option value="B-CD">CD</option>
    </select>
    The idea is select presente from the select name stato_dipendente :


    Code:
    <select name="stato_dipendente" onchange="setCities(this)">
    <option>Seleziona stato giornaliero</option>
    <option value="Assente">Assente</option>
    <option value="Presente">Presente</option>
    </select></td>
    When select presente in the select name stato_dipendente, sending variable as the function setCities.

    The function setCities receives this variable and in the select name tipo_stato_giornaliero :

    1) Variable A ===> regiondb["PresenteA"]
    2) Variable B ===> regiondb["PresenteB"]

    The error is:

    Error: 'regionVar' is undefined
    Link:
    http://www12.asphost4free.com/viki1967/select.htm

    Thanks for your help...
    Viki

  2. #2
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well. The JavaScript console doesn't lie. Where is regionVar defined in your code?

  3. #3
    Non-Member
    Join Date
    Aug 2007
    Posts
    494
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Pepejeria View Post
    Well. The JavaScript console doesn't lie. Where is regionVar defined in your code?

    This is the problem ....

    Where "regionVar" be defined ?

  4. #4
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, you programmed that code, didn't you? What meaning should this variable have?

  5. #5
    Non-Member
    Join Date
    Aug 2007
    Posts
    494
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry, but not familiar with Javascript....

    1) The variable regionVar is A when in select D1 is selected value DVD or value DVDR .

    2) The variable regionVar is B when in select D1 is selected value CDR or value CD .

    Code:
    <select size="8" name="D1" multiple>
        <option>Select</option>
        <option value="A-DVD">DVD</option>
        <option value="A-DVDR">DVDR</option>
        <option value="B-CDR">CDR</option>
        <option value="B-CD">CD</option>
    </select>
    The idea is select presente from the select name stato_dipendente :


    Code:
    <select name="stato_dipendente" onchange="setCities(this)">
    <option>Seleziona stato giornaliero</option>
    <option value="Assente">Assente</option>
    <option value="Presente">Presente</option>
    </select></td>
    When select presente in the select name stato_dipendente, sending variable regionVar as the function setCities.

    The function setCities receives this variable regionVar and in the select name tipo_stato_giornaliero :

    1) Variable A ===> regiondb["PresenteA"]
    2) Variable B ===> regiondb["PresenteB"]

  6. #6
    Non-Member
    Join Date
    Aug 2007
    Posts
    494
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <html>
    
    <&#37;
    
    Session.LCID = 1040
    response.expires = -1500 
    response.AddHeader "PRAGMA", "NO-CACHE"
    response.CacheControl = "PRIVATE"
    
    Function SELECTED(firstVal, secondVal())
    	For e = 0 To UBound(secondVal)
    		If cSTR(firstVal) = cSTR(secondVal(e)) then
    		   SELECTED = " selected=""selected"""
    		End If
    	Next
    End Function
    
    %>
    
    <head>
    
    <script language="javascript">
    
    <!--
    
    var regiondb = new Object()
    regiondb["Assente"] = [{value:"Ferie", text:"Ferie"},
                          {value:"Festivit&#224; abolita", text:"Festivit&#224; abolita"},
                          {value:"Malattia", text:"Malattia"},
                          {value:"Infortunio", text:"Infortunio"},
                          {value:"Riposo Fisiologico", text:"Riposo Fisiologico"},
                          {value:"Riposo Compensativo", text:"Riposo"},
                          {value:"Permesso retribuito", text:"Permesso"},
                          {value:"Permesso Sind./ARCA", text:"Permesso Sind"},
                          {value:"Ricovero Ospedaliero", text:"Ricovero"},
                          {value:"Part-time", text:"Part-time"},
                          {value:"Assemblea Sindacale", text:"Assemblea"},
                          {value:"Sciopero", text:"Sciopero"},
                          {value:"Aspettativa", text:"Aspettativa"},
                          {value:"Carica Pubblica", text:"Carica Pubblica"},
                          {value:"Da giustificare", text:"Da giustificare"}];
                          
    regiondb["PresenteA"] = [{value:"Fuori sede", text:"Fuori sede"},
                            {value:"In sede", text:"In sede"}];
                            
    regiondb["PresenteB"] = [{value:"Monoperatore", text:"Monoperatore"},
                            {value:"Coppia", text:"Coppia"},
                            {value:"Formazione a tre", text:"Formazione a tre"},
                            {value:"Appoggio", text:"Appoggio"},
                            {value:"Fuori sede", text:"Fuori sede"},
                            {value:"In sede", text:"In sede"}];
     
     
    function setCities(chooser) 
    
    {
        var newElem;
        var where = (navigator.appName == "Microsoft Internet Explorer") ? -1 : null;
        var cityChooser = chooser.form.elements["tipo_stato_giornaliero"];
        while (cityChooser.options.length)
        
     {
            cityChooser.remove(0);
        }
        
        // regionVar
        var regionVar = document.getElementById('reg').split("-")[0];
        
        var choice = chooser.options[chooser.selectedIndex].value;
        var db = regiondb[choice+regionVar]; // regionVar is A or B
    
        newElem = document.createElement("option");
        newElem.text = "Seleziona valore";
        newElem.value = "";
        cityChooser.add(newElem, where);
        if (choice != "") 
        
        {
            for (var i = 0; i < db.length; i++) 
            
            {
                newElem = document.createElement("option");
                newElem.text = db[i].text;
                newElem.value = db[i].value;
                cityChooser.add(newElem, where);
            }
        }
    
    } 
       
        // -->
        
    </script>
    
    </head>
    
    <body>
    
    <form method="POST" action="page.asp">
    
    <select size="8" id="reg" name="SelectMultipla" multiple="multiple">
    
    <%
    
    valore_strVariabile = Request.QueryString("SelectMultipla")
    If len(valore_strVariabile) = 0 then 
    
    %> 
                                            
    	<option>Select</option>
    	<option value="A-DVD">DVD</option>
    	<option value="A-DVDR">DVDR</option>
    	<option value="B-CDR">CDR</option>
    	<option value="B-CD">CD</option>
    
    <% 
    
    Else 
    
    If InStr(valore_strVariabile,",") > 0 then
       valore_strVariabile = Replace(valore_strVariabile," ","")
       elementi = split(valore_strVariabile,",")
    Else
       elementi = array(valore_strVariabile)
    End If
    
    %>
         
         <option>Select</option>
         <option value="A-DVD" <%=SELECTED("A-DVD", elementi)%>>DVD</option>
         <option value="A-DVDR" <%=SELECTED("A-DVDR", elementi)%>>DVDR</option>
         <option value="B-CDR" <%=SELECTED("B-CDR", elementi)%>>CDR</option>
         <option value="B-CD" <%=SELECTED("B-CD", elementi)%>>B-CDR</option>
         
    <% End If %>	
    
    </select>
    	
    
    <select name="stato_dipendente" onchange="setCities(this)">
    	<option>Seleziona stato giornaliero</option>
    	<option value="Assente">Assente</option>
    	<option value="Presente">Presente</option>
    </select></td>
    
    <select name="tipo_stato_giornaliero" onchange="onChangeStatus(this);">
    	<option>Seleziona tipo stato giornaliero</option>
    </select>
    
    <input type="submit" value="vai" />
    	
    </form>
    
    </body>
    
    </html>
    Error is:

    Object doens't support this property or method


  7. #7
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try this:

    Code:
    var reg = document.getElementById('reg');
    var regionVar = reg.options[reg.selectedIndex].value.split("-")[0];


  8. #8
    Non-Member
    Join Date
    Aug 2007
    Posts
    494
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, but error is :

    Object doens't support this property or method

    Code:
    <html>
    
    
    
    <head>
    
    <script language="javascript">
    
    <!--
    
    var regiondb = new Object()
    regiondb["Assente"] = [{value:"Ferie", text:"Ferie"},
                          {value:"Festivit&#224; abolita", text:"Festivit&#224; abolita"},
                          {value:"Malattia", text:"Malattia"},
                          {value:"Infortunio", text:"Infortunio"},
                          {value:"Riposo Fisiologico", text:"Riposo Fisiologico"},
                          {value:"Riposo Compensativo", text:"Riposo"},
                          {value:"Permesso retribuito", text:"Permesso"},
                          {value:"Permesso Sind./ARCA", text:"Permesso Sind"},
                          {value:"Ricovero Ospedaliero", text:"Ricovero"},
                          {value:"Part-time", text:"Part-time"},
                          {value:"Assemblea Sindacale", text:"Assemblea"},
                          {value:"Sciopero", text:"Sciopero"},
                          {value:"Aspettativa", text:"Aspettativa"},
                          {value:"Carica Pubblica", text:"Carica Pubblica"},
                          {value:"Da giustificare", text:"Da giustificare"}];
                          
    regiondb["PresenteA"] = [{value:"Fuori sede", text:"Fuori sede"},
                            {value:"In sede", text:"In sede"}];
                            
    regiondb["PresenteB"] = [{value:"Monoperatore", text:"Monoperatore"},
                            {value:"Coppia", text:"Coppia"},
                            {value:"Formazione a tre", text:"Formazione a tre"},
                            {value:"Appoggio", text:"Appoggio"},
                            {value:"Fuori sede", text:"Fuori sede"},
                            {value:"In sede", text:"In sede"}];
     
    function setCities(chooser) 
    
    {
        var newElem;
        var where = (navigator.appName == "Microsoft Internet Explorer") ? -1 : null;
        var cityChooser = chooser.form.elements["tipo_stato_giornaliero"];
        while (cityChooser.options.length)
        
     {
            cityChooser.remove(0);
        }
        
    
    
    // regionVar
        
        var reg = document.getElementById('reg');
        var regionVar = reg.options[reg.selectedIndex].value.split("-")[0];
    
    // regionVar
        
        
        var choice = chooser.options[chooser.selectedIndex].value;
        var db = regiondb[choice+regionVar]; // regionVar is A or B
    
        newElem = document.createElement("option");
        newElem.text = "Seleziona valore";
        newElem.value = "";
        cityChooser.add(newElem, where);
        if (choice != "") 
        
        {
            for (var i = 0; i < db.length; i++) 
            
            {
                newElem = document.createElement("option");
                newElem.text = db[i].text;
                newElem.value = db[i].value;
                cityChooser.add(newElem, where);
            }
        }
    
    } 
       
        // -->
        
    </script>
    
    </head>
    
    <body>
    
    <form method="POST" action="page.asp">
    
    <select size="8" id="reg" name="SelectMultipla" multiple="multiple">
    
     
                                            
    	<option>Select</option>
    	<option value="A-DVD">DVD</option>
    	<option value="A-DVDR">DVDR</option>
    	<option value="B-CDR">CDR</option>
    	<option value="B-CD">CD</option>
    
    	
    
    </select>
    	
    
    <select name="stato_dipendente" onchange="setCities(this)">
    	<option>Seleziona stato giornaliero</option>
    	<option value="Assente">Assente</option>
    	<option value="Presente">Presente</option>
    </select></td>
    
    <select name="tipo_stato_giornaliero" onchange="onChangeStatus(this);">
    	<option>Seleziona tipo stato giornaliero</option>
    </select>
    
    <input type="submit" value="vai" />
    	
    </form>
    
    </body>
    
    </html>

  9. #9
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    do you have a link of which I can see the error? Or could you post the entire error as we can't see what line its failing on?


  10. #10
    Non-Member
    Join Date
    Aug 2007
    Posts
    494
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by gRoberts View Post
    do you have a link of which I can see the error? Or could you post the entire error as we can't see what line its failing on?
    Try this page, please:

    http://www.complessobandisticopalomb...967/select.asp

  11. #11
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for that. From what I can see the cause of the error is the fact that db isn't being populated unless you select presente.

    I would put checks in place to check to see whether db is null or not, ie

    Code:
    var db = regiondb[choice+regionVar]; // regionVar is A or B
    if(typeof(db) == 'undefined') {
    alert('db empty');
    return;
    }
    Assente is within the regiondb object but as the object is Assente instead of AssenteA or AssenteB its not being found.


  12. #12
    Non-Member
    Join Date
    Aug 2007
    Posts
    494
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, many thanks for your answer.

    This solution, but it is right? :

    Code:
    var regiondb = new Object()
    regiondb["AssenteA"] = [{value:"Ferie", text:"Ferie"},
                          {value:"Festivit&#224; abolita", text:"Festivit&#224; abolita"},
                          {value:"Malattia", text:"Malattia"},
                          {value:"Infortunio", text:"Infortunio"},
                          {value:"Riposo Fisiologico", text:"Riposo Fisiologico"},
                          {value:"Riposo Compensativo", text:"Riposo"},
                          {value:"Permesso retribuito", text:"Permesso"},
                          {value:"Permesso Sind./ARCA", text:"Permesso Sind"},
                          {value:"Ricovero Ospedaliero", text:"Ricovero"},
                          {value:"Part-time", text:"Part-time"},
                          {value:"Assemblea Sindacale", text:"Assemblea"},
                          {value:"Sciopero", text:"Sciopero"},
                          {value:"Aspettativa", text:"Aspettativa"},
                          {value:"Carica Pubblica", text:"Carica Pubblica"},
                          {value:"Da giustificare", text:"Da giustificare"}];
                          
    regiondb["AssenteB"] = [{value:"Ferie", text:"Ferie"},
                          {value:"Festivit&#224; abolita", text:"Festivit&#224; abolita"},
                          {value:"Malattia", text:"Malattia"},
                          {value:"Infortunio", text:"Infortunio"},
                          {value:"Riposo Fisiologico", text:"Riposo Fisiologico"},
                          {value:"Riposo Compensativo", text:"Riposo"},
                          {value:"Permesso retribuito", text:"Permesso"},
                          {value:"Permesso Sind./ARCA", text:"Permesso Sind"},
                          {value:"Ricovero Ospedaliero", text:"Ricovero"},
                          {value:"Part-time", text:"Part-time"},
                          {value:"Assemblea Sindacale", text:"Assemblea"},
                          {value:"Sciopero", text:"Sciopero"},
                          {value:"Aspettativa", text:"Aspettativa"},
                          {value:"Carica Pubblica", text:"Carica Pubblica"},
                          {value:"Da giustificare", text:"Da giustificare"}];                      
                          
    regiondb["PresenteA"] = [{value:"Fuori sede", text:"Fuori sede"},
                            {value:"In sede", text:"In sede"}];
                            
    regiondb["PresenteB"] = [{value:"Monoperatore", text:"Monoperatore"},
                            {value:"Coppia", text:"Coppia"},
                            {value:"Formazione a tre", text:"Formazione a tre"},
                            {value:"Appoggio", text:"Appoggio"},
                            {value:"Fuori sede", text:"Fuori sede"},
                            {value:"In sede", text:"In sede"}];

  13. #13
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Basically you are taking the value of one select element and then the value of another and using this to generate an index which will be used to return data from an JSON object with the same index/name,

    ie PresenteA

    If you don't create an entry in your JSON object with the same name then it cant return it, which results in errors.


  14. #14
    Non-Member
    Join Date
    Aug 2007
    Posts
    494
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by gRoberts View Post
    Basically you are taking the value of one select element and then the value of another and using this to generate an index which will be used to return data from an JSON object with the same index/name,

    ie PresenteA

    If you don't create an entry in your JSON object with the same name then it cant return it, which results in errors.
    I understand.

    Add some code to check the choice is not Assente when adding regionVar, i.e. the line

    Code:
    var db = regiondb[choice+regionVar]; // regionVar is A or B
    should only be for Presente.

    If choice is Assente, don't add regionVar:

    Code:
    if (choice == "Presente") choice += regionVar;
    var db = regiondb[choice];
    http://www.complessobandisticopalomb...967/select.asp

    But not work, why?

  15. #15
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It may be worth doing

    Code:
    var db = regiondb[choice+regionVar]; // regionVar is A or B
    if(!db || typeof(db) == 'undefined')
    db = regiondb[choice];


  16. #16
    Non-Member
    Join Date
    Aug 2007
    Posts
    494
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  17. #17
    Non-Member
    Join Date
    Aug 2007
    Posts
    494
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, working !!!!

    Many thanks gRoberts for your help....

    http://www.complessobandisticopalomb...967/select.asp

  18. #18
    Non-Member
    Join Date
    Aug 2007
    Posts
    494
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi, i have new problem...

    Please follow this sequence in this page web:

    http://www.complessobandisticopalomb...967/select.asp

    1) No selection in the select name="SelectMultipla";
    2) Select value Assente in the select name="stato_dipendente";
    3) The select name="tipo_stato_giornaliero" is empty.

    1) No selection in the select name="SelectMultipla";
    2) Select value Presente in the select name="stato_dipendente";
    3) The alert window warning db empty.

    You can see alert window warning when value Assente is selected in the select name="stato_dipendente" ???

    Thanks...

  19. #19
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    At the moment I am on holiday and unable to access the internet for this type of query/issue, so if you are able to wait I will try and get back to you asap.


  20. #20
    Non-Member
    Join Date
    Aug 2007
    Posts
    494
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wait.... happy holidays !!!!!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •