•
•
•
•
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
![]() |
•
•
Join Date: May 2007
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
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
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
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:
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."
"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."
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.
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."
"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."
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!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
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."
"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."
•
•
•
•
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!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb JavaScript / DHTML / AJAX Marketplace
•
•
•
•
ajax asp cross-browser javascript menu with few lines of code developer development firefox home html internet javascript javascript smooth scrolling scroll smoothly window document position javascript tab menu with rounded corners generator microsoft msdn office prevent javascript menu from getting hidden under flash movies site software sql vista web
- Previous Thread: only show in IE but not firefox,any clue why?
- Next Thread: How to Load the dll into javascript?



Linear Mode