Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
92
rated 0 times [  94] [ 2]  / answers: 1 / hits: 36599  / 11 Years ago, tue, april 30, 2013, 12:00:00

I have a selectbox with parameters as the value in the option, set like this:



<option value={$i.tileid}androoftiletypeeq{$i.model}andproducenteq{$i.producent}>{$i.name} {$i.$title}</option>


I am trying to replace all and and eq to & and =, but I can only get my javascript to replace the first occurrence. The form is named / ID'ed rooftile_select



$(#rooftile_select).change(function(event) {

event.preventDefault();

var data = $(#rooftile_select).serialize();
var pathname = window.location;
var finalurl = pathname+'&'+data;

var replaced = finalurl.replace(and, &).replace(eq, =);
});


The last parameters in finalurl then looks like this:



&rid=56&rooftiletype=9andproducenteqs


Am I missing something?


More From » jquery

 Answers
0
var replaced = finalurl.replace(/and/g, '&').replace(/eq/g, '=');


This should do the trick. With the g after the / you're saying that you want to replace all occurences.


[#78513] Monday, April 29, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kevonmoisesf

Total Points: 693
Total Questions: 101
Total Answers: 128

Location: Reunion
Member since Mon, Dec 28, 2020
4 Years ago
kevonmoisesf questions
Sat, Jan 23, 21, 00:00, 3 Years ago
Tue, Feb 18, 20, 00:00, 4 Years ago
Wed, Jun 12, 19, 00:00, 5 Years ago
;