473,398 Members | 2,188 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

string building and hidden form fields

162 100+
Hello,

I'm trying to get this script to work, but my deep rooted PHP syntax is messing my JS up.

I have a flash file that calls this JS function. It basically adds a number to a comma separated string. this works fine.
Expand|Select|Wrap|Line Numbers
  1. var select = "";
  2. function selectCounty (cid){ select = cid + "," + select; }    
  3.  
The flash also calls this function to remove a value from the string. The removeVal() function works. though, the *select* variable is not reforming into a string. I'm missing how to then put the array into a form that this is part of.
Expand|Select|Wrap|Line Numbers
  1. function unSelectCounty (cid){ 
  2.     // split the *select* string into an array
  3.     var select_array = select.split(/,/);
  4.  
  5.     // remove *cid* value from array
  6.     unselect = removeVal(select_array, cid);
  7.  
  8.     // reset *select* var
  9.     select = "";
  10.     for (i=0;i<unselect.length;i++){ if (unselect[i] != ''){ select = unselect[i] + "," + select; } }
  11. }
  12. function removeVal(arr, valToRemove){
  13.     // Normalize to a string like !val!!val!!val!
  14.     var s = '!' + arr.join('!!') + '!';
  15.     // Remove targeted values with delimiters
  16.     s = s.replace(new RegExp('!' + valToRemove + '!', 'g'), '');
  17.     // Remove delimiter added to end in step 1
  18.     s = s.replace(/^!/, '');
  19.     // Remove delimiter added to start in step 1
  20.     s = s.replace(/!$/, '');
  21.     // Convert to array
  22.     return s.split('!!');
  23. }
  24.  
Please help with these two problems-

1) i cant get the *select* string in unSelectCounty() to reform correctly.
2) i am unsure what to write so that the value of *select* is passed in POST form array. it can accept it either as an array or a string.

Thanks.
May 29 '07 #1
3 1300
dmjpro
2,476 2GB
So r u trying to pass an an array in form fields???
right???

but mind it ... no array can be sent.
all the parameter value is sent as string.
if u want to send multiple value in one string then in the server side u should tokenize the string.
or keep each value in multiple values in multiple fields.
best of luck.

kind regards.
dmjpro.
May 29 '07 #2
empiresolutions
162 100+
ok i got a little farther, updated this function to -
Expand|Select|Wrap|Line Numbers
  1.     function unSelectCounty (cid){ 
  2.         // split the *select* string into an array
  3.         select_array = select.split(/,/);
  4.         // remove *cid* value from array
  5.         unselect = removeVal(select_array, cid);
  6.         // reset *select* var
  7.         select = unselect.join(',');
  8.     }
  9.  
  10.  
I still need to know about how to attach my *select* var to a hidden form field. this can be passed as a string.
May 29 '07 #3
acoder
16,027 Expert Mod 8TB
join() makes the array a string, so you can simply set the value of the hidden field:
Expand|Select|Wrap|Line Numbers
  1. document.getElementById(hiddenid).value=select;
May 29 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Randell D. | last post by:
Folks, Perhaps someone can figure this out - this is 'the process of my script' I have a form whereby I can add multiple contacts to a single address. There is only one...
1
by: mark.reichman | last post by:
First off.. Thanks to Grant Wagner for help in a previous thread related to this one. I am at a total loss... I have multiple fields in a form with the same name. Lets call the fields with the...
13
by: Dan R Brown | last post by:
I have a large form that is generated dynamically in a jsp using xml / xslt. So, to break up this form into several "tabbed" sections, I break up the form using <div> tags. Each <div...
1
by: Sam Wuebben | last post by:
I would like to add a few hidden field values to a form as it is submited via JavaScript. I have a static page shopping site that uses MIVA shopping cart. Some of the pages are getting quite...
1
by: Glenn | last post by:
Searching through google groups, I have not found anyone able to modify the query string of a request. I was hoping to make the query string as short as possible so that a search with many...
5
by: NTE | last post by:
Access 2000, My application has a main form that the users interact with. There are 2 hidden fields. When they select "filter by form" from the menu, the hidden fields become visble. Is...
5
by: Roshawn Dawson | last post by:
Hi, Are hidden fields passed in the querystring when a form is posted back? If they are, must the hidden fields be server controls in order to access them from .net code? Thanks, Roshawn
3
by: c676228 | last post by:
Hi everyone, I just realized that it's so important to validate each string, I mean 'each' before you insert data from asp page into database. I guess some customers just copy data from some...
11
by: RipperT | last post by:
Don't know if this group covers web apps, but here goes. In VS 2005, I am trying to get variables to hold thier values during postback from the server. I convert a text box's user-keyed value to an...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.