?
Solved

Help! -- Need to trim both ends of a string....

Posted on 2003-11-17
7
Medium Priority
?
280 Views
Last Modified: 2006-11-17
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.forms[0].strPassedAgency.value.split(",");
  var objForm = document.forms[0]
      
      if(arrChecked.length == 1) {
            form2.allAgencies.checked=true;
      }
      else {
        for(i=0;i<arrChecked.length;i++){
              if(objForm.elements[arrChecked[i]]){
                objForm.elements[arrChecked[i]].checked=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...
0
Comment
Question by:saabStory
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 25

Expert Comment

by:devic
ID: 9768003
hi saabStory,

Include file not found :(
0
 
LVL 31

Accepted Solution

by:
GwynforWeb earned 1000 total points
ID: 9768031
to strip the "'"  out use this

<script>
str="'abcde'"
srtStrip=str.replace(/\'/g,"")
alert(str+"\n"+srtStrip)
</script>
0
 
LVL 31

Expert Comment

by:GwynforWeb
ID: 9769413
ie

var arrChecked = window.opener.document.forms[0].strPassedAgency.value.split(",");
var objForm = document.forms[0]
arrChecked=arrChecked.replace(/\'/g,"")
0
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 
LVL 11

Expert Comment

by:Zontar
ID: 9769898
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.forms[0].strPassedAgency.value.split(",");
> arrChecked=arrChecked.replace(/\'/g,"")

Are you sure this will work, Gwyn? The first expression returns an array...
0
 
LVL 11

Expert Comment

by:Zontar
ID: 9769900
That should have been

stripped = originalString.splice(1, -1);

Sorry.
0
 

Author Comment

by:saabStory
ID: 9771535
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!
0
 
LVL 31

Expert Comment

by:GwynforWeb
ID: 9771881
Thanks, GfW
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question