SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Oct 2003
    Location
    pdx
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    form input values, cookies

    when this page loads i want the "name" input type field to automatically display the resuld of my cookie. if this page does not have a cookie set yet it shouldn't put anything in the field. when i use the script below, the cookies get set fine, and i can alert them when the page comes in, but the value will not show in the input field. when alerting alert(window.document.cart3form.name.value) the returned value is "undefined". anybody know how to get the unput field to enter right?


    <form name="cart3form">
    <script language="JavaScript" type="text/JavaScript">

    alert(getCookie('name2')); // shows correct value of name2

    window.document.cart3form.name.value = getCookie('name2');

    alert(window.document.cart3form.name.value); // retuns "undefined"

    document.write('<td width="60%" align="left"><input type="text" name="name" maxlength="40" size="31" onBlur="setCookie('+"'name2'"+', this.value)"> </td>');

    </script>
    </form>

  2. #2
    SitePoint Zealot cmorbutts's Avatar
    Join Date
    Apr 2002
    Location
    Sydney, Australia
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The reason why no it's returning undefined is because you haven't written the <input> tag out yet. Try this instead and see if it works.

    <form name="cart3form">
    <script language="JavaScript" type="text/JavaScript">

    alert(getCookie('name2')); // shows correct value of name2

    document.write('<td width="60%" align="left"><input type="text" name="name" maxlength="40" size="31" onBlur="setCookie('+"'name2'"+', this.value)"> </td>');

    window.document.cart3form.name.value = getCookie('name2');

    alert(window.document.cart3form.name.value); //
    retuns "undefined"

    </script>
    </form>

    I would recommend you give your form elements an id attribute instead and use the getElementById in Javascript.

  3. #3
    SitePoint Member
    Join Date
    Oct 2003
    Location
    pdx
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    worked perfectly thanks


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
  •