This script works fine if all form fields have one value, but what do you do
if one of the form fields was a multiple select?
Example: status=blue&sta tus=red
function getParams() {
var index = document.URL.in dexOf('?');
var params = new Array();
if ( index != -1 ) {
var nameValuePairs
=document.URL.s ubstring(index+ 1,document.URL. length).split(' &');
for ( var i=0; i<nameValuePair s.length; i++ ) {
nameVal = nameValuePairs[i].split('=');
params[nameVal[0]] = nameVal[1];
}
} return params;
}
var mystat=unescape (params["status"]);
John 5 14644
Instead of storing just the value, store the value as an Array. That way a
single param can have multiple values.
change: for ( var i=0; i<nameValuePair s.length; i++ ) { nameVal = nameValuePairs[i].split('='); params[nameVal[0]] = nameVal[1];
}
To:
for ( var i=0; i<nameValuePair s.length; i++ ) {
nameVal = nameValuePairs[i].split('=');
if (params[nameVal[0]] == null) {//param doesn't exist so create a
new array
params[nameVal[0]] = [nameVal[1]];
}else{ //param already exists so add to the array
params[nameVal[0]].push(nameVal[1]);
}
}
"johkar" <no********@lin k.net> wrote in message
news:0e******** *********@newsr ead3.news.pas.e arthlink.net... This script works fine if all form fields have one value, but what do you
do if one of the form fields was a multiple select?
Example: status=blue&sta tus=red
function getParams() { var index = document.URL.in dexOf('?'); var params = new Array(); if ( index != -1 ) { var nameValuePairs =document.URL.s ubstring(index+ 1,document.URL. length).split(' &'); for ( var i=0; i<nameValuePair s.length; i++ ) { nameVal = nameValuePairs[i].split('='); params[nameVal[0]] = nameVal[1];
}
} return params; }
var mystat=unescape (params["status"]);
John
Thanks for the reply. Where is the new array declared? What is push, and
what does it do? Support?
John
"Oz" <oz@synovic.com > wrote in message
news:kc******** ************@co mcast.com... Instead of storing just the value, store the value as an Array. That way a single param can have multiple values.
change: for ( var i=0; i<nameValuePair s.length; i++ ) { nameVal = nameValuePairs[i].split('='); params[nameVal[0]] = nameVal[1];
}
To:
for ( var i=0; i<nameValuePair s.length; i++ ) { nameVal = nameValuePairs[i].split('='); if (params[nameVal[0]] == null) {//param doesn't exist so create a new array params[nameVal[0]] = [nameVal[1]]; }else{ //param already exists so add to the array params[nameVal[0]].push(nameVal[1]); } }
snip
Arrays can be declared a couple of ways
var array = new Array();
or
var array = [ ]; //just short hand
So the first time the param is encountered a the value was stored in an
array in the following line params[nameVal[0]] = [nameVal[1]];
this could also be written params[nameVal[0]] = new Array(nameVal[1]);
push is a method on Array objects that automatically adds a new entry to the
end of an array. so instead of increasing the number of
members in an array by using:
myArray[myArray.length] = new Object();
you can simply use:
myArray.push(ne w Object());
For complete documentation check out http://devedge.netscape.com/library/...nce/array.html http://devedge.netscape.com/library/.../contents.html
"johkar" <no********@lin k.net> wrote in message
news:jt******** ********@newsre ad4.news.pas.ea rthlink.net... Thanks for the reply. Where is the new array declared? What is push, and what does it do? Support?
John
"Oz" <oz@synovic.com > wrote in message news:kc******** ************@co mcast.com... Instead of storing just the value, store the value as an Array. That way
a single param can have multiple values.
change: for ( var i=0; i<nameValuePair s.length; i++ ) { nameVal = nameValuePairs[i].split('='); params[nameVal[0]] = nameVal[1];
}
To:
for ( var i=0; i<nameValuePair s.length; i++ ) { nameVal = nameValuePairs[i].split('='); if (params[nameVal[0]] == null) {//param doesn't exist so create
a new array params[nameVal[0]] = [nameVal[1]]; }else{ //param already exists so add to the array params[nameVal[0]].push(nameVal[1]); } } snip
Mike wrote: So the first time the param is encountered a the value was stored in an array in the following line > > params[nameVal[0]] = [nameVal[1]]; this could also be written > > params[nameVal[0]] = new Array(nameVal[1]);
Depends on the implementation of ECMAScript and the value of nameVal[1].
The Array constructor function also takes the number of array elements
as first argument in some implementations . So the Array literal is the
saner way here.
BTW Oz, johkar, Mike: You are top-posting, please read http://www.netmeister.org/news/learn2quote.html and stop
that.
PointedEars This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: PT |
last post by:
I got a problem. And thats.....
First of all, I got these three tables.
------------------- ------------------ ----------------------
tblPerson tblPersonSoftware tblSoftware
------------------- ------------------ ----------------------
PID PName PID* SID* SID SWName
--- ----- --- --- --- ------
1 Thomas 1 1 ...
|
by: Rick Caborn |
last post by:
Does anyone know of a way to execute sql code from a dynamically built
text field?
Before beginning, let me state that I know this db architecture is
built solely for frustration and I hope to make it better soon.
Unfortunately, there is never a non-crucial time in which we can do an
upgrade, so we are stuck for now.
Point 1:
There are multiple tables: students, courses, cross-reference
|
by: Drew |
last post by:
I have a db table like the following,
UID, int auto-increment
RegNo
Person
Relation
YearsKnown
Now here is some sample data from this table,
|
by: DC Gringo |
last post by:
I have two listboxes, the first of which is an autopostback=true that allows
multiple row selection. When I select multiple values (by holding down CTL)
in the first one, it should query the second one. I seem unable to do this
as it only sends back the first item I select whether I have the CTL key
down or not. Upon the return trip, I can select another one, but it still
only sends value for the last one I selected.
-- MY LISTBOX --...
|
by: Chris A via AccessMonster.com |
last post by:
I have an interesting problem that I have yet to come accross that I can't
change data structure on because it is an export from filemaker I am
reformatting for another dept. anyway. I have a table like so...
Table 1
Field1 Field2 Field3
E1 April 2006 AA, BB, CC
E2 April 2006 AA, BB, CC,DD, EE
E3 April 2006 AA, BB
| |
by: Diego |
last post by:
Hi everybody!
I'm using DB2 PE v8.2.3 for linux. I've defined a database with the
following schema:
ANNOTATION(ID,AUTHOR,TEXT)
ANNOTATION_BOOK(ANNOTATION_ID,OBJECT_ID)
BOOK(ID,AUTHOR,TITLE).
Between the book and annotation entities there is a many-to-many
|
by: areef.islam |
last post by:
Hi, I am kinda new to javascript and I am having this problem with
selecting multiple options from a select tag. Hope someone can help me
out here.
here is my code
///////////////////////////////////////////////////////////////////////////////////////
<form action="whatever.php" method="post">
<select name="zip_code"
onchange="makeRequest('getCity.php?state='+this.form.zip_code.options.value)"
multiple="multiple" size="20">
|
by: scott |
last post by:
Hello all,
I am ripping my hair out over this and maybe someone could help.
I have a site that has groups and subgroups of those groups that all
have int id's.
I am trying to have a multiple select drop down (could select more than
one group) like the following:
|
by: rosie2006 |
last post by:
Environment: .net2.0 over oracle
Problem? a simple select statement within a DetailsView that gets two parameter values from a GridView SelectedValue.
It might be valuable to understand that to pull a single record from this particular table requires two parameters.
What follows defies understanding.
The desired query:
<asp:SqlDataSource .....
|
by: englishman69 |
last post by:
Hello,
I have been banging my head against this one for a while... Searches online have revealed many different proposals for correcting my issue but none that I can follow! My basic situation is this, I have a page which uses multiple postbacks to generate a list of dynamic text boxes with appropriate labels. However, when I do the final postback to enter the values in the dynamic textboxes into the database the values seem to become...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |