Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

jvascript String object-replace  RSS feed

 
amarkirt saroay
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • 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 !
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65825
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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?


  •  
    Jeanne Boyarsky
    author & internet detective
    Sheriff
    Posts: 36406
    454
    Eclipse IDE Java VI Editor
    • Mark post as helpful
    • send pies
    • 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
    • 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.
    >
     
    Amit Ghorpade
    Bartender
    Posts: 2856
    10
    Fedora Firefox Browser Java
    • Mark post as helpful
    • send pies
    • 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
    • Quote
    • Report post to moderator
    Using escape() method ,it worked!
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!