saabStory
asked on
Help! -- Need to trim both ends of a string....
I have a large rather complicated app I'm trying to get ready for a demo on Wednesday and am having a problem with some of the data I'm passing around.
Basically, I have a popup window where I select a water quality agency or agencies. The selections are bounded by single quotes (to drop into the db query later). A typical selection would have the value of 'TCEQ', when it's passed to the query.
If someone wants to modify the selections, they can re-open the window and, thanks to code from Fritz the Blank, the selections they previously made are checked when the window re-opens. The problem I have now is that for the db queries to work, I need to have the values in single quotes. But when the window reloads, I need to strip out the single quotes for the javascript that controls the checkboxes to work properly.
The function that he wrote to do this is:
function fillForm(){
var arrChecked = window.opener.document.for ms[0].strP assedAgenc y.value.sp lit(",");
var objForm = document.forms[0]
if(arrChecked.length == 1) {
form2.allAgencies.checked= true;
}
else {
for(i=0;i<arrChecked.lengt h;i++){
if(objForm.elements[arrChe cked[i]]){
objForm.elements[arrChecke d[i]].chec ked=true;
}
}
}
}
In other words if I have a string that is 'BREC','TCEQ','TIAER', I need to modify the function so that it strips out the "'" from the values after the array is split so that all that comes out is BREC TCEQ and TIAER.
I hope this makes at least minimal sense. If you need to see the whole thing in action, go to http://test.c-b.com/brazos and select 'Get Data'. From that page the item in question is on the 'Agencies' popUp under Search Criteria. Selecting any of the agencies and submitting will cause the values to appear in the gray Passed Agency Values box on the right.
I won't be able to pick this back up for the next 3 or 4 hours - but I'll be back online once I get home and get the kids to bed.
Thanks for the help and sorry for any confusion...
Basically, I have a popup window where I select a water quality agency or agencies. The selections are bounded by single quotes (to drop into the db query later). A typical selection would have the value of 'TCEQ', when it's passed to the query.
If someone wants to modify the selections, they can re-open the window and, thanks to code from Fritz the Blank, the selections they previously made are checked when the window re-opens. The problem I have now is that for the db queries to work, I need to have the values in single quotes. But when the window reloads, I need to strip out the single quotes for the javascript that controls the checkboxes to work properly.
The function that he wrote to do this is:
function fillForm(){
var arrChecked = window.opener.document.for
var objForm = document.forms[0]
if(arrChecked.length == 1) {
form2.allAgencies.checked=
}
else {
for(i=0;i<arrChecked.lengt
if(objForm.elements[arrChe
objForm.elements[arrChecke
}
}
}
}
In other words if I have a string that is 'BREC','TCEQ','TIAER', I need to modify the function so that it strips out the "'" from the values after the array is split so that all that comes out is BREC TCEQ and TIAER.
I hope this makes at least minimal sense. If you need to see the whole thing in action, go to http://test.c-b.com/brazos and select 'Get Data'. From that page the item in question is on the 'Agencies' popUp under Search Criteria. Selecting any of the agencies and submitting will cause the values to appear in the gray Passed Agency Values box on the right.
I won't be able to pick this back up for the next 3 or 4 hours - but I'll be back online once I get home and get the kids to bed.
Thanks for the help and sorry for any confusion...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ie
var arrChecked = window.opener.document.for ms[0].strP assedAgenc y.value.sp lit(",");
var objForm = document.forms[0]
arrChecked=arrChecked.repl ace(/\'/g, "")
var arrChecked = window.opener.document.for
var objForm = document.forms[0]
arrChecked=arrChecked.repl
If you're sure that the single quotes will always be at the beginning and end of each string, you can also use
stripped = originalString.splice(1, 1);
> var arrChecked = window.opener.document.for ms[0].strP assedAgenc y.value.sp lit(",");
> arrChecked=arrChecked.repl ace(/\'/g, "")
Are you sure this will work, Gwyn? The first expression returns an array...
stripped = originalString.splice(1, 1);
> var arrChecked = window.opener.document.for
> arrChecked=arrChecked.repl
Are you sure this will work, Gwyn? The first expression returns an array...
That should have been
stripped = originalString.splice(1, -1);
Sorry.
stripped = originalString.splice(1, -1);
Sorry.
ASKER
Thanks for the help - it's working now. Sorry to get back to you all so late - DSL was down at home last night.
Thanks again!
Thanks again!
Thanks, GfW
Include file not found :(