www.webdeveloper.com
Results 1 to 2 of 2

Thread: [RESOLVED] Relation between two select with array

  1. #1
    Join Date
    Apr 2007
    Location
    Italy
    Posts
    104

    resolved [RESOLVED] Relation between two select with array

    Hi to All,

    I have 3 menus.

    In the first menu I select an email adress.

    According to the email selected, in the second menu appears a problem list with an option called "Free Text"

    I would like that,
    ONLY when a user choose email1 with the second option "Free Text",
    OR when a user choose email2 with the unique option of "Free Text",
    in the third menu appears the voice "Choose priority ..." with the other two options: urgent, normal ..

    With this code, now the goal is ok only for email1,
    with email2 happens nothing ...


    Thanks a lot in advance !!!

    <head>
    //
    var summary_db = new Object()
    var prior_db = new Object()
    summary_db["email1"] = [{value:"Problems of 1 level, text:"Problems of 1 level"},
    {value:"Problems of schedule", text:"Problems of schedule"},
    {value:"Free Text", text:"Free Text"}];
    summary_db["email2"] = [{value:"Free Text", text:"Free Text"}];
    prior_db["Problems of 1 level"] = [{value:"2 hours", text:"2 hours"}];
    prior_db["Problems of schedule"] = [{value:"4 hours", text:"4 hours"}];
    prior_db["Free Text"] = [{value:"Normal (5 days)", text:"Normal (5 days)"},{value:"Urgent (1 day)", text:"Urgent (1 day)"}];
    //
    function setIssue(chooser) {
    var newElem;
    var where = (navigator.appName == "Microsoft Internet Explorer") ? -1 : null;
    var Iss_Chooser = chooser.form.elements["iss_sum"];
    while (Iss_Chooser.options.length) {
    Iss_Chooser.remove(0);
    }
    var choice = chooser.options[chooser.selectedIndex].value;
    var db = summary_db[choice];
    if (choice == "email1") {
    newElem = document.createElement("option");
    newElem.text = "Choose an Issue ...";
    newElem.value = "Choose Issue ...";
    Iss_Chooser.add(newElem, where);
    }
    for (var i = 0; i < db.length; i++) {
    newElem = document.createElement("option");
    newElem.text = db[i].text;
    newElem.value = db[i].value;
    Iss_Chooser.add(newElem, where);
    }
    }
    //
    function setPriority(chooser) {
    var newElem;
    var where = (navigator.appName == "Microsoft Internet Explorer") ? -1 : null;
    var prChooser = chooser.form.elements["priority"];
    while (prChooser.options.length) {
    prChooser.remove(0);
    }
    var choice = chooser.options[chooser.selectedIndex].value;
    var db = prior_db[choice];
    if (choice=="Free Text") {
    newElem = document.createElement("option");
    newElem.text = "Choose priority ...";
    newElem.value = "Choose priority ...";
    prChooser.add(newElem, where);
    }
    for (var i = 0; i < db.length; i++) {
    newElem = document.createElement("option");
    newElem.text = db[i].text;
    newElem.value = db[i].value;
    prChooser.add(newElem, where);
    }
    }
    //
    </script>
    </head>

    <body>
    <form method="POST" webbot-onSubmit language="JavaScript" name="FrontPage_Form1">

    <select name="mess" id="mess" onchange="setIssue(this)">
    <option value="<%=objRS("Mess")%>" selected><%=objRS("Mess")%></option>
    <option value="email1">Mail 1</option>
    <option value="email2">Mail 2</option>
    </select>


    <select id="iss_sum" name="iss_sum" onchange="setPriority(this)">
    <option value="<%=objRS("Summary")%>" selected><%=objRS("Summary")%></option>
    </select>


    <select name="priority" id="priority">
    <option value="<%=objRS("Priority")%>" selected><%=objRS("Priority")%></option>
    </select>

    </body>

  2. #2
    Join Date
    Apr 2007
    Location
    Italy
    Posts
    104
    I have solved the problem in this way ...

    I put in red the new code added

    <head>
    //
    var summary_db = new Object()
    var prior_db = new Object()
    summary_db["email1"] = [{value:"Problems of 1 level, text:"Problems of 1 level"},
    {value:"Problems of schedule", text:"Problems of schedule"},
    {value:"Free Text", text:"Free Text"}];
    summary_db["email2"] = [{value:"Free Text", text:"Free Text"}];
    prior_db["Problems of 1 level"] = [{value:"2 hours", text:"2 hours"}];
    prior_db["Problems of schedule"] = [{value:"4 hours", text:"4 hours"}];
    prior_db["Free Text"] = [{value:"Normal (5 days)", text:"Normal (5 days)"},{value:"Urgent (1 day)", text:"Urgent (1 day)"}];
    //
    function setIssue(chooser) {
    var newElem;
    var where = (navigator.appName == "Microsoft Internet Explorer") ? -1 : null;
    var Iss_Chooser = chooser.form.elements["iss_sum"];
    while (Iss_Chooser.options.length) {
    Iss_Chooser.remove(0);
    }
    var choice = chooser.options[chooser.selectedIndex].value;
    var db = summary_db[choice];
    if (choice == "email1") {
    newElem = document.createElement("option");
    newElem.text = "Choose an Issue ...";
    newElem.value = "Choose Issue ...";
    Iss_Chooser.add(newElem, where);
    }
    for (var i = 0; i < db.length; i++) {
    newElem = document.createElement("option");
    newElem.text = db[i].text;
    newElem.value = db[i].value;
    Iss_Chooser.add(newElem, where);
    }
    }
    //
    function setPriority(chooser) {
    var newElem;
    var where = (navigator.appName == "Microsoft Internet Explorer") ? -1 : null;
    var prChooser = chooser.form.elements["priority"];
    while (prChooser.options.length) {
    prChooser.remove(0);
    }
    var choice = chooser.options[chooser.selectedIndex].value;
    var db = prior_db[choice];
    if (choice=="Free Text") {
    newElem = document.createElement("option");
    newElem.text = "Choose priority ...";
    newElem.value = "Choose priority ...";
    prChooser.add(newElem, where);
    }
    for (var i = 0; i < db.length; i++) {
    newElem = document.createElement("option");
    newElem.text = db[i].text;
    newElem.value = db[i].value;
    prChooser.add(newElem, where);
    }
    }
    //
    function setJump(chooser) {
    var choice = chooser.options[chooser.selectedIndex].value;
    if (choice=="mail2") {
    var newElem;
    var where = (navigator.appName == "Microsoft Internet Explorer") ? -1 : null;
    var jpChooser = chooser.form.elements["priority"];
    while (jpChooser.options.length) {
    jpChooser.remove(0);
    }
    newElem = document.createElement("option");
    newElem.text = "Choose priority ...";
    newElem.value = "Choose priority ...";
    jpChooser.add(newElem, where);
    newElem = document.createElement("option");
    newElem.text = "Normal (5 days)";
    newElem.value = "Normal (5 days)";
    jpChooser.add(newElem, where);
    newElem = document.createElement("option");
    newElem.text = "Urgent (1 day)";
    newElem.value = "Urgent (1 day)";
    jpChooser.add(newElem, where);
    }
    }
    //
    </script>
    </head>

    <body>
    <form method="POST" webbot-onSubmit language="JavaScript" name="FrontPage_Form1">

    <select name="mess" id="mess" onchange="setIssue(this);setJump(this)">
    <option value="<%=objRS("Mess")%>" selected><%=objRS("Mess")%></option>
    <option value="email1">Mail 1</option>
    <option value="email2">Mail 2</option>
    </select>


    <select id="iss_sum" name="iss_sum" onchange="setPriority(this)">
    <option value="<%=objRS("Summary")%>" selected><%=objRS("Summary")%></option>
    </select>


    <select name="priority" id="priority">
    <option value="<%=objRS("Priority")%>" selected><%=objRS("Priority")%></option>
    </select>

    </body>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles