Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

form input values and cookies

Status
Not open for further replies.

cesarcesar

Programmer
Mar 5, 2003
30
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=&quot;cart3form&quot;>
<script language=&quot;JavaScript&quot; type=&quot;text/JavaScript&quot;>

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

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

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

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

</script>
</form>
 
.name is a reserved keyword,
alert(document.Form.name) //this will give u the form's name


alert(window.document.cart3form.name) //this must give cart3form

try using field name as name1...

Known is handfull, Unknown is worldfull
 
thanks for the reply, fixed the problem by switching two lines of code, i was setting the value of the input field before actually setting the input field, below is my new script.


<form name=&quot;cart3form&quot;>
<script language=&quot;JavaScript&quot; type=&quot;text/JavaScript&quot;>

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

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

</script>
</form>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top