...

View Full Version : Sortserialize and hash output problem



Null
12-11-2007, 10:17 AM
Don't know if anyone knows how this works, but I though, let's give it a shot.

I currently have the following code (javascript) to get a hash:


function serialize(s)
{
serial = $.SortSerialize(s);
alert(serial.hash);
};

Now this has the following output:
sort3[]=links&sort3[]=images

I want it to output:
links,images

How to do this?
sort3[]= needs to be filtered
& needs to replaced by ,

I've tried things like:


function serialize(s)
{
serial = $.SortSerialize(s);
alert(serial.hash);
var hash = serial.hash;
var temp = hash.replace(new RegExp( "sort3\[\]=", "gi" ),'');

and


function serialize(s) {
serial = $.SortSerialize(s);
var hash = serial.hash;
var temp = hash.replace(/sort3\[\]=/gi,'');
alert(serial.hash);
};


But none worked :( Hope you guys can help.

Many thx,

_Null

ps 1: I am a noob so plz be gentle :)
ps 2: For now I use the alert function to check/see the hash output.

shyam
12-12-2007, 06:54 AM
alert(serial.replace(/sort3\[\]=/gi, '').replace(/&/g, ','));

Null
12-12-2007, 10:53 AM
alert(serial.replace(/sort3\[\]=/gi, '').replace(/&/g, ','));
Thx, but this results in a non working alert.

Eventually I want this output filtered in a text field so I can upload it to a db. Perhaps itīs easier to filter it as a string? Maybe you guys can give me examples of how to do that? (since the alert doesn't work/causes issues?)

Thanks

shyam
12-12-2007, 02:44 PM
did u try this?

alert(serial.hash.replace(/sort3\[\]=/gi, '').replace(/&/g, ','));

Null
12-12-2007, 02:49 PM
did u try this?

alert(serial.hash.replace(/sort3\[\]=/gi, '').replace(/&/g, ','));

Excelent, that worked :thumbsup:. Thank you very much!

Next stop, getting the alert into a input field (http://www.codingforums.com/showthread.php?t=129562)

oesxyl
12-12-2007, 04:08 PM
Excelent, that worked :thumbsup:. Thank you very much!

Next stop, getting the alert into a input field (http://www.codingforums.com/showthread.php?t=129562)

In this thread I understand that you want to set the value of the input to what you have in alert box but in http://www.codingforums.com/showthread.php?t=129562) I answer to the question "how to retrive the value from the input?".

So, if you want to set/retrive the value of the input to something you can do:

Identify the object with name="serial"


var s = document.getEelemtById('serial');


set the value to what you need:


s.value = serial.hash.replace(/sort3\[\]=/gi, '').replace(/&/g, ',');


retrive the value from input and for example use into an alert box:


alert(s.value)


maybe this http://www.javascriptkit.com/ could help you more

best regards



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum