Results 1 to 6 of 6

Thread: hash output into a formfield

  1. #1
    Join Date
    Aug 2005
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default hash output into a formfield

    Hi,

    The folowing (small part)javascriptcode returns a hash in a pop-up:
    Code:
    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:

    Code:
    <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

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Replace:

    Code:
    alert(serial.hash);
    with:

    Code:
    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:

    HTML Code:
    <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.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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):

    Code:
    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.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  4. #4
    Join Date
    Aug 2005
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by jscheuer1 View Post
    Replace:

    Code:
    alert(serial.hash);
    with:

    Code:
    document.getElementById('serial').value=serial.hash;
    HTML Code:
    <input type="button" onclick="serialize('sort3'); " value="Update" />
    Thank you that worked. I have 1 final question:
    I had the hash stripped using:
    Code:
    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

  5. #5
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    If that set replacements was working for you, just remove the outer set of parenthesis that contain the string value for the alert method:

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

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. #6
    Join Date
    Aug 2005
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Tank you very much, this fixed it. Was working on this for weeks now, realy should posted sooner

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •