• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Tim Cooke
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
Saloon Keepers:
  • Piet Souris
Bartenders:

jvascript String object-replace

 
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have a string "ROGER & CO & BAYS" and I have stored it in a javascript variable var1.
But on displaying ROGER & CO & BAYS my jsp throws Object error/exception,
I think its a problem in interpreting the special character '&'
Now how can I replace the character '&' by '&' in a javascript?

I tried using var1.replace("&"," & amp");

but its not working.
Please help !
 
Sheriff
Posts: 67762
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't you think it'd be a good idea to:

  • Show us the actual code?


  • Show us the actual error message?


  •  
    author & internet detective
    Posts: 42271
    951
    Eclipse IDE VI Editor Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    What is the value if var1 if you alert it?
     
    amarkirt saroay
    Ranch Hand
    Posts: 167
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    This is a Flex cum Js cum JSP issue.
    I want to pass a string variable containing ampersand ('&') character onto a URL through javascript but my string gets stripped when it encounters the first '&' in it !!!


    I have an array of strings which get passed from an mxml file or method call as below:

    Code in my mxml file:

    noOfCols=4
    rowData is an array with 5 strings passed:
    "12-34"
    "56-78"
    "12-90"
    "ABC & CO &RODGER"
    "1234"

    ExternalInterface.call("funToOpenPopUpWindow",columns,rowData,noOfCols)

    Code inside my js file:

    function funToOpenPopUpWindow(columns,rowData,noOfCols){
    var j=0;

    var RowElements=new Array();

    RowElements="";


    while(j<noOfCols)
    {

    if(rowData[j]== "" || rowData[j] == null){
    RowElements+="BLANK";
    }
    else{
    alert("hi 2"+rowData[j])

    //rowData[j] = rowData[j].replace("&","%26") // This is what I am stuck at what to do?
    //rowData[j] = rowData[j].replaceAll('&','/&') //I dont know if its right
    RowElements+=rowData[j];


    alert(RowElements)
    }
    RowElements+="@";
    j++;
    }



    var url="popUp.action";
    var popup =url+"cols="+cols+"&RowElements="+RowElements;

    window.showModalDialog(popup, self,"dialogHeight:700px;dialogWidth:600px, resizable=no ,scrollbars=no");

    }

    I am not able to pass the character '&' inside the string "ABC & CO &RODGER" as '&' ,Actually as soon as it sees '&' in the string when while loop reaches rowData[3] ,it stops at 'ABC ' and doesnt go beyond that.I am not finding whats the issue with display of '&' in the string being passed,I need to pass this string and append '@' to it and then pass it as a parameter to the URL inorder to open a new window.

    Please help me fix this !

    I tried the replace method for strings in Javascript but it could not work.
    >
     
    Bartender
    Posts: 2856
    10
    Firefox Browser Fedora Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    amarkirt saroay wrote:This is a Flex cum Js cum JSP issue.


    I see no JSP in here,its all Javascript
     
    amarkirt saroay
    Ranch Hand
    Posts: 167
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Using escape() method ,it worked!
     
    Don't get me started about those stupid light bulbs.
    reply
      Bookmark Topic Watch Topic
    • New Topic