Closed Thread Icon

Topic awaiting preservation: JavaScript search/replace query string (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=8887" title="Pages that link to Topic awaiting preservation: JavaScript search/replace query string (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: JavaScript search/replace query string <span class="small">(Page 1 of 1)</span>\

 
Kaniz
Bipolar (III) Inmate

From:
Insane since: Jun 2003

posted posted 10-03-2003 04:57

I have a URL which looks something like this ...
http://xx.xx.xxx.xx/olgc/contacts.asp?action=&opt=&orderby=Promo&page=3

and, what I'd like to do, is be able to replace the orderby=Promo with various things, such as last_name/etc, and re-load the page. Currently, what I have is at the top of the table, is headers with things like <a href="Javascript:reorder('Last_Name');>

and the functions..

code:
function getOrder(pair)
{
var temp = pair.split("=")
return temp[0];
}
function changeorder(neworder)
{
var httpArray = window.location.toString().split('&');
for(x=0;x<httpArray.length;x++) {
if(getOrder(httpArray[x]) == 'orderby')
httpArray[x] = "orderby=" + neworder;

}

window.location.replace(httpArray.join("&"));

}



This works, however.. I have a nagging feeling this isnt the best way of going about it. I have re-written it once (first version managed to be 2x as long for some reason...), but still think it 'could be better'. Not sure why I'm so focused on a trivial little piece of code, I guess its just me not wanting to read 60 pages of stats homework

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 10-03-2003 06:12

<script>
str = window.location.toString();
alert(str.replace(/orderby=[^&]*(&

Kaniz
Bipolar (III) Inmate

From:
Insane since: Jun 2003

posted posted 10-03-2003 20:29

Thanks.

I allways have this nagging feeling that I *should* take it upon myself to learn regex expressions. But, they allways scare me



« BackwardsOnwards »

Show Forum Drop Down Menu