User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 361,629 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,182 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 886 | Replies: 6
Reply
Join Date: May 2007
Posts: 3
Reputation: mariecon is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
mariecon mariecon is offline Offline
Newbie Poster

multiselectable dropdown

  #1  
Jan 3rd, 2008
Hello everyone,

I'm a newbie in AJAX. I have found a code in the web that uses AJAX and PHP (withjavascripts). It works well but i want to have a multiselectable dropdown. How can i retrieve the value of the multiselctable dropdown thruogh its javascript???

Here's the code that retrieve the value of the dropdown:

<script>
var xmlHttp
function showUser(str)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="php_code1.php" //the name of your php file - ajax code
url=url+"?q="+str
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("txtHint").innerHTML=xmlHttp.responseText //txtHint is the name of the div that can be replaced by the output of php file
}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
//Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
</script>

***How can i modify it so it will retrieve the value of the multiselectable dropdown which is an array? Please help me...

regards,
mariecon
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2006
Location: India
Posts: 6,689
Reputation: ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold 
Rep Power: 23
Solved Threads: 312
Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Rebellion Revamped

Re: multiselectable dropdown

  #2  
Jan 4th, 2008
Take a look at this post. It loops through all the options of a select box and checks for those which are selected. You can then construct a query string based on that.

For eg. if you have a select box name "selBox" from which you have selected two options "one" and "two", your query string should look like: url += "&selBox=one&selBox=two"; Here one and two would come from the snippet I just pointed you to.
Last edited by ~s.o.s~ : Jan 4th, 2008 at 10:59 am.
"I don't accept change. I don't deserve to live."

"Working a real job is a win if you're lazy, greedy, or unmotivated. If you're average, you fit right in. And if you're above average, the basic terms of employment and premise of the arrangement is against your interests."
Reply With Quote  
Join Date: Jun 2006
Location: India
Posts: 6,689
Reputation: ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold 
Rep Power: 23
Solved Threads: 312
Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Rebellion Revamped

Re: multiselectable dropdown

  #3  
Jan 4th, 2008
Also don't forget to encode the query string to handle special characters or characters which already have a predetermined meaning in the querystring. (eg. &)

It would be better if you used a form serializing function which would serialize the entire form and return the resulting query string.
Last edited by ~s.o.s~ : Jan 4th, 2008 at 10:59 am.
"I don't accept change. I don't deserve to live."

"Working a real job is a win if you're lazy, greedy, or unmotivated. If you're average, you fit right in. And if you're above average, the basic terms of employment and premise of the arrangement is against your interests."
Reply With Quote  
Join Date: Sep 2005
Posts: 591
Reputation: digital-ether will become famous soon enough digital-ether will become famous soon enough 
Rep Power: 5
Solved Threads: 37
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Posting Pro

Re: multiselectable dropdown

  #4  
Jan 7th, 2008
i know mootools has a method that will serialize the form into a query string. I'm sure other popular JS libraries will have one too.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote  
Join Date: Jun 2006
Location: India
Posts: 6,689
Reputation: ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold 
Rep Power: 23
Solved Threads: 312
Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Rebellion Revamped

Re: multiselectable dropdown

  #5  
Jan 7th, 2008
Yes, there are many libraries out there which do this but many people are against using libraries which result in a visible bloat. Implementing our own serialize function or by using the functions from one of the existing libraries in a separate JS file would be much more feasible.
"I don't accept change. I don't deserve to live."

"Working a real job is a win if you're lazy, greedy, or unmotivated. If you're average, you fit right in. And if you're above average, the basic terms of employment and premise of the arrangement is against your interests."
Reply With Quote  
Join Date: Sep 2005
Posts: 591
Reputation: digital-ether will become famous soon enough digital-ether will become famous soon enough 
Rep Power: 5
Solved Threads: 37
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Posting Pro

Help Re: multiselectable dropdown

  #6  
Jan 7th, 2008
Originally Posted by ~s.o.s~ View Post
Yes, there are many libraries out there which do this but many people are against using libraries which result in a visible bloat. Implementing our own serialize function or by using the functions from one of the existing libraries in a separate JS file would be much more feasible.


There is really no bloat in mootools. I think the whole lib compressed is about 4k. You can just get part of the library that does the serialization. That would be even less, around 2-3k. Most libraries have something around these lines.

You don't get much learning from using libraries though. Implementing your own give you a much better understanding of the solution.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote  
Join Date: May 2007
Posts: 3
Reputation: mariecon is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
mariecon mariecon is offline Offline
Newbie Poster

Re: multiselectable dropdown

  #7  
Jan 14th, 2008
Thanks for your reply.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb JavaScript / DHTML / AJAX Marketplace
Thread Tools Display Modes

Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 6:43 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC