PDA

View Full Version : hash output into a formfield



Null
12-17-2007, 02:43 PM
Hi,

The folowing (small part)javascriptcode returns a hash in a pop-up:

unction serialize(s)
{
serial = $.SortSerialize(s);
alert(serial.hash);
};
</SCRIPT>

Now I want it's output in a formfield and NOT in a alert. I've tried this:


<form action="" method="post">
<input name="serial" id="serial" value="" />
<p class="submit alignleft"><input type="submit" onclick="serialize("sort3"); " value="Update" /></p>
</form>

So onclick (on the submit button) the value should be put into the field. But it aint working. (at the moment the onclick triggers the alert, wich does work)

How to fix this?

More info: (s) = the id of the divlist wich I want to serialize (get the hash output), so onclick="serialize("sort3"); get's the hash of this div.

Many thanks,

Null

jscheuer1
12-17-2007, 03:48 PM
Replace:


alert(serial.hash);

with:


document.getElementById('serial').value=serial.hash;

Also, if you want to see the result of this on the page, don't use a submit button to do it. Use a regular button and nest your quote marks properly:


<input type="button" onclick="serialize('sort3'); " value="Update" />

Another thing, don't use undeclared variables, and try using a different name for the variable than for the id and name of the element you are changing the value of. Some browsers can get very finicky about such things.

jscheuer1
12-17-2007, 05:50 PM
My previous post might be helpful. I'm not sure because you've given so little information. I can't even tell if you mean a technical hash value or just something that you are calling a hash. That might not be important, but may. And what code you've given looks poorly written and error ridden.

So, even if you do the sensible thing (there are other approaches) and just take whatever string you have and assign it to the form element's value property (as outlined in a more specific way in my previous post):


document.getElementById('text_input_id').value=string;

There could be other problems. If you need more help:

Please post a link to the page on your site that contains the problematic code so we can check it out.

Null
12-17-2007, 07:41 PM
Replace:


alert(serial.hash);

with:


document.getElementById('serial').value=serial.hash;


<input type="button" onclick="serialize('sort3'); " value="Update" />


Thank you that worked. I have 1 final question:
I had the hash stripped using:

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

But that wont work anymore. How can I use this stripping in the new (above given) code?

Thanks

jscheuer1
12-17-2007, 08:25 PM
If that set replacements was working for you, just remove the outer set of parenthesis that contain the string value for the alert method:


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

Null
12-17-2007, 10:08 PM
Tank you very much, this fixed it. Was working on this for weeks now, realy should posted sooner :D