Greywacke Posted October 29, 2013 Share Posted October 29, 2013 hi everyone, i am currently having an issue with the following excerpt of javascript - particularly the "regular expressions not wanting to replace". case 19: // set where Prim_Att_Val document.getElementById("ajaxbg").style.visibility = "visible"; var val = document.form_services.where_primattval.options[form_services.where_primattval.selectedIndex].value; // new constraint var title = document.getElementById("table_results").tHead.children[1].title; // current constraints //salert("re = ^/[ AND]*" + quote(" `Prim_Att_Val` = ""+where["Prim_Att_Val"]+""") + "/g"); //salert("val = "+val); //salert("title = "+title); if (whereo["Prim_Att_Val"]==-1) { document.getElementById("table_results").tHead.children[1].title += ((wherecnt>0)?" AND":"")+" `Prim_Att_Val` = ""+val+"""; where["Prim_Att_Val"] = val; whereo["Prim_Att_Val"] = wherecnt; wherecnt++; } else { //salert(whereo["Prim_Att_Val"]); //salert(val); document.getElementById("table_results").tHead.children[1].title = title.replace(re = new RegExp("/"+quote("`Prim_Att_Val` = "" + where["Prim_Att_Val"]+""")+"/g"),(val!="")?"`Prim_Att_Val` = ""+val+""":val); if (!where["Prim_Att_Val"]) whereo["Prim_Att_Val"] = -1; salert(title); salert(re.toString()); salert("`Prim_Att_Val` = ""+val+"""); salert(whereo["Prim_Att_Val"]); where["Prim_Att_Val"] = val; } document.getElementById("ajaxbg").style.visibility = "hidden"; break; salert is a custom function which prints to a div at the top of the screen. same results could be achieved by calling alert, it's just neater with all the data being kept and new lines being written. what is the issue with line 680 - it is not replacing the values as expected? in case 13, it does however - this does not have the string inserted into the regular expression to search for... anybody, please help! Link to comment Share on other sites More sharing options...
Greywacke Posted October 29, 2013 Author Share Posted October 29, 2013 ah - the answer was: as i was using a compiled regular expression, it was better to pass the modifiers in the second argument of the object document.getElementById("table_results").tHead.children[1].title = title.replace(re = new RegExp(quote("`Prim_Att_Val` = "" + where["Prim_Att_Val"]+"""),"g"),((val!="")?"`Prim_Att_Val` = ""+val+""":val)); hope this helps many others with similar endeavours! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now