Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old June 10th, 2005, 02:02 AM
Registered User
Points: 1,897, Level: 17
Points: 1,897, Level: 17 Points: 1,897, Level: 17 Points: 1,897, Level: 17
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2005
Location: Mumbai, Maharastra, India.
Posts: 352
Thanks: 14
Thanked 0 Times in 0 Posts
Send a message via Yahoo to rupen
Default populating dropdown values

Inside a form, I have a drop down menu list of manager names from Access database. When a user select a manager name from drop down list, that manager's team members should added into another drop down , How could I accomplish this without reloading the page because i don't want to loose all others "entered" data on this form.

  #2 (permalink)  
Old June 10th, 2005, 02:21 AM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

-----------------------cut n paste start-----------------------
<html>
 <HEAD>
  <title></title>
  <SCRIPT LANGUAGE="JavaScript">
    function move(fbox, tbox) {
    var arrFbox = new Array();
    var arrTbox = new Array();
    var arrLookup = new Array();
    var i;
    for (i = 0; i < tbox.options.length; i++) {
    arrLookup[tbox.options[i].text] = tbox.options[i].value;
    arrTbox[i] = tbox.options[i].text;
    }
    var fLength = 0;
    var tLength = arrTbox.length;
    for(i = 0; i < fbox.options.length; i++) {
    arrLookup[fbox.options[i].text] = fbox.options[i].value;
    if (fbox.options[i].selected && fbox.options[i].value != "") {
    arrTbox[tLength] = fbox.options[i].text;
    tLength++;
    }
    else {
    arrFbox[fLength] = fbox.options[i].text;
    fLength++;
       }
    }
    arrFbox.sort();
    arrTbox.sort();
    fbox.length = 0;
    tbox.length = 0;
    var c;
    for(c = 0; c < arrFbox.length; c++) {
    var no = new Option();
    no.value = arrLookup[arrFbox[c]];
    no.text = arrFbox[c];
    fbox[c] = no;
    }
    for(c = 0; c < arrTbox.length; c++) {
    var no = new Option();
    no.value = arrLookup[arrTbox[c]];
    no.text = arrTbox[c];
    tbox[c] = no;
       }
    }
  </script>
</HEAD>
<BODY>
<form name="combo_box">
<table>
 <tr>
  <td><select name="list1" >
       <option value="1">All Blacks</option>
       <option value="2">Are the</option>
       <option value="3">Greatest</option>
       <option value="4">Rugby Team</option>
       <option value="5">In the world</option>
      </select></td>
  <td align="center" valign="middle"><input type="button" onClick="move(this.form.list2,this.form.list1)" value="<<"><input type="button" onClick="move(this.form.list1,this.form.list2)" value=">>"></td>
  <td><select size="3" name="list2" style="width:150"></select></td>
 </tr>
</table>
</form>
</body>
</html>
-----------------------cut n paste finish-----------------------

Wind is your friend
Matt
  #3 (permalink)  
Old June 10th, 2005, 02:26 AM
Friend of Wrox
Points: 686, Level: 9
Points: 686, Level: 9 Points: 686, Level: 9 Points: 686, Level: 9
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2005
Location: Kolkata, West Bengal, India.
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well Rupen,
You can use Javascript functions for populating one dropdown by selecting value from another dropdown. this function has to be attached to the onchange function of the master dropdown control like
<select "controlname" onchange="somefunction()">

step 1:
1st pick up the value of manager & teammemember values from the database using ASP.
step 2:
convert ASP variable values into Javascript variables
step 3:
write function in javascript using the length of the Manager dropdown control field to loop it through it using a for...loop. then populate the member control dropdown using new Option object.

This can be done very easily if you confident enough with array variables.

I hope though this may not look very clear but it works if you can follow the steps and are confident with Javascript.

in Javascript first
  #4 (permalink)  
Old June 10th, 2005, 04:02 AM
Registered User
Points: 1,897, Level: 17
Points: 1,897, Level: 17 Points: 1,897, Level: 17 Points: 1,897, Level: 17
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2005
Location: Mumbai, Maharastra, India.
Posts: 352
Thanks: 14
Thanked 0 Times in 0 Posts
Send a message via Yahoo to rupen
Default

Thanks for reply,

But for step 1, it is totally different seane,
teammambers name depends on manager say, manager1 will have membr1,membr2 while manager2 will have membr2,membr2 i.e. teammember's name depends on selection of manager's name, so i can't populate it in advance,

for step 2, how do i convert asp varible to javascript variable?

The problem here is access to database from javascript function.

i will be happy if you can provide some code.


  #5 (permalink)  
Old July 20th, 2005, 10:51 AM
Registered User
Points: 1,897, Level: 17
Points: 1,897, Level: 17 Points: 1,897, Level: 17 Points: 1,897, Level: 17
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2005
Location: Mumbai, Maharastra, India.
Posts: 352
Thanks: 14
Thanked 0 Times in 0 Posts
Send a message via Yahoo to rupen
Default

Hi Guys,

Can I have any update on above topic? It's burning my lots of calories...

Thanks in Advance.

Rupen Anjaria.
We CAN'T avoid problems, but of course can solve it.
  #6 (permalink)  
Old August 8th, 2005, 05:23 AM
Friend of Wrox
 
Join Date: Oct 2004
Location: delhi, delhi, India.
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

Hii Rupen
Please visit this link ,It will help you :)
http://js-examples.com/javascript/?run=683

Cheers :)

vinod
  #7 (permalink)  
Old August 8th, 2005, 09:05 AM
Registered User
Points: 1,897, Level: 17
Points: 1,897, Level: 17 Points: 1,897, Level: 17 Points: 1,897, Level: 17
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2005
Location: Mumbai, Maharastra, India.
Posts: 352
Thanks: 14
Thanked 0 Times in 0 Posts
Send a message via Yahoo to rupen
Default

Hi Vinod,

Thanks for link. But this is done in js, i have done such thing in js, but the problem is that i have to copy all vaues from db to js array(even they have use same in this link.) but that comsumes lot resouce, instead all thing should be done in ASP.

like this:
http://www.tek-tips.com/faqs.cfm?fid=3978

The problem with above example is that i can't retain values.




Rupen Anjaria.
We CAN'T avoid problems, but can solve it.
  #8 (permalink)  
Old August 8th, 2005, 10:56 AM
Friend of Wrox
 
Join Date: Oct 2004
Location: delhi, delhi, India.
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

Hii Rupen!!
Other alternative is to use hidden frames then populate the values of second dropdownlist form that frame.If you don't want to load all the data simulataneously.

Other alternative is ActiveX object, it works with IE



Cheers :)

vinod
  #9 (permalink)  
Old August 8th, 2005, 11:04 AM
Registered User
Points: 1,897, Level: 17
Points: 1,897, Level: 17 Points: 1,897, Level: 17 Points: 1,897, Level: 17
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2005
Location: Mumbai, Maharastra, India.
Posts: 352
Thanks: 14
Thanked 0 Times in 0 Posts
Send a message via Yahoo to rupen
Default

Hi Vinod,

Sorry to say, but I realy don't have any idea about these alternative, i be greatly thankfull to u if u can give any link explaing such solution.

Thank you so much.....


Rupen Anjaria.
We CAN'T avoid problems, but can solve it.
  #10 (permalink)  
Old August 9th, 2005, 06:13 AM
Friend of Wrox
 
Join Date: Oct 2004
Location: delhi, delhi, India.
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

Hii Rupen !!
No probs
Hope this will help you


<script>
var req;
function blr()
{
&nbsp;url="http://myurl_ip/vinodR&D/optionvalue.html"
    req = false;
    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest) {
        alert("hii")
        try {
            req = new XMLHttpRequest();
        } catch(e) {
            req = false;
        }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
        &nbsp;&nbsp;&nbsp;try {
            req = new ActiveXObject("Msxml2.XMLHTTP");
        &nbsp;&nbsp;} catch(e) {
            try {
                &nbsp;&nbsp;req = new ActiveXObject("Microsoft.XMLHTTP");
            } catch(e) {
                &nbsp;&nbsp;req = false;
            }
        }
    }
    if(req) {
        req.onreadystatechange = processReqChange;
        req.open("GET", url, true);
        req.send();
    }
}


function processReqChange()
{

    if (req.readyState == 4) {


        if (req.status == 200) {


                    &nbsp;var xmlDOM = new ActiveXObject("Microsoft.XMLDOM");
                        xmlDOM.loadXML(req.ResponseText);

                        var oNode = xmlDOM.documentElement.firstChild;

                        var n=0;
                        selectedvalue=document.myform.myid.value
                        var outputstr
                        outputstr=""
                        &nbsp;&nbsp;if(oNode != null)
                        &nbsp;&nbsp;{

                                    &nbsp;&nbsp;&nbsp;while (oNode != null)
                                    &nbsp;&nbsp;&nbsp;{
                                        &nbsp;if(selectedvalue==n)
                                        &nbsp;&nbsp;{
                                        &nbsp;&nbsp;&nbsp;outputstr=oNode.text
                                        &nbsp;&nbsp;&nbsp;break;
                                        &nbsp;&nbsp;&nbsp;}
                                        &nbsp;&nbsp;&nbsp;oNode = oNode.nextSibling;
                                        n++;
                                    &nbsp;&nbsp;&nbsp;}

                            } var obj
                                                                            parentobj=document.getElementById("myselbox")

                                                                            objarr=outputstr.split("|")

                                                                            for(i=0;i<objarr.length;i++)
                                                                            {

                                                                            chld=objarr[i].split("~")
                                                                            myname=chld[0];
                                                                            myvalue=chld[1];
                                                                            &nbsp;obj=new Option(myname,myvalue)
                                                                            parentobj[i]=obj
                                                                            }
            }
    }
}
</script>
<body onload="blr()">

<form name="myform">

Select Your Choice<select id="myid" name="myid" onchange="blr()">
<option value="1">AllRecord With 1</option>
<option value="2">AllRecord With 2</option>
<option value="3">AllRecord With 3</option>
<option value="4">AllRecord With 4</option>
</select>
<br>
Dynamic Select Box<select id="myselbox" name="myselbox">
</select>


</form>

</body>


<response>
&nbsp;&nbsp;<option1>Name1~1|Name2~2|Name3~3|Name4 ~4|Name5~5|Name6~6|Name7~7|Name8~8|Name9~9|Name10~ 10|Name11~11</option1>
&nbsp;&nbsp;<option1>Vinod1~1|Vinod2~2|Vinod3~3|Vi nod4~4|Vinod5~5|Vinod6~6|Vinod7~7|Vinod8~8|Vinod9~ 9|Vinod10~10|Vinod11~11</option1>
&nbsp;&nbsp;<option1>Rupen1~1|Rupen2~2|Rupen3~3|Ru pen4~4|Rupen5~5|Rupen6~6|Rupen7~7|Rupen8~8|Rupen9~ 9|Rupen10~10|Rupen11~11</option1>
&nbsp;&nbsp;<option1>Hello1~1|Hello2~2|Hello3~3|He llo4~4|Hello5~5|Hello6~6|Hello7~7|Hello8~8|Hello9~ 9|Hello10~10|Hello11~11</option1>
&nbsp;&nbsp;<option1>Vijay1~1|Vijay2~2|Vijay3~3|Vi jay4~4|Vijay5~5|Vijay6~6|Vijay7~7|Vijay8~8|Vijay9~ 9|Vijay10~10|Vijay11~11</option1>

</response>

**********optionvalue.html End **********

Note:-
1>Please change ur url as per ur requirement.
2>You can enhance ur code by getting only those rows for which u r selecting values
&nbsp;I mean you can avoid to loop
&nbsp;if(selectedvalue==n)
                                        &nbsp;&nbsp;{
                                        &nbsp;&nbsp;&nbsp;outputstr=oNode.text
                                        &nbsp;&nbsp;&nbsp;break;
                                        &nbsp;&nbsp;&nbsp;}
by making ensure that the row returned by ur optionvalue.html/asp/php/jsp whtever is returning is the ur option value.
Here i used all the combinations so that I donĂ³t have to write the asp code
2>Same techniq u can use with hidden frames :)



Cheers :)

vinod




Similar Threads
Thread Thread Starter Forum Replies Last Post
Populating dropdown within a datagrid ninel ASP.NET 2.0 Professional 2 May 31st, 2006 02:41 AM
Populating dropdown within a datagrid ninel ASP.NET 2.0 Basics 7 May 26th, 2006 03:26 PM
Populating dropdown within a datagrid ninel General .NET 0 May 26th, 2006 12:27 PM
populating a dropdown list with values from datab akshay144 VS.NET 2002/2003 5 May 12th, 2006 10:15 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.