How do I write javascript cookies from a form and then print the info in an alert or hidden div? -
how use javascript write cookies form fields, , print info in alert or hidden div?
here example of have tried far.....
<script type="text/javascript"> function cookieform() { document.cookie = "name_first" + encodeuricomponent(document.forms[0].name_first.value); } function printcustomerinfo() { var querydata = decodeuricomponent(document.cookie); var queryarray = querydata.split(";"); if (document.cookie) { window.alert("your info. is:" + queryarray[0]); window.alert[0].name_last.value = queryarray[1].substring(queryarray[1].lastindexof("=") + 1); } } </script> <input type="submit" value="submit" onclick="cookieform(), printcustomerinfo()"/>
first, you're missing "=" in cookie string:
document.cookie = "name_first=" + encodeuricomponent(document.forms[0].name_first.value);
second, querydata has no ";" split by, , no last name value - @ least show here.
this not understand:
window.alert[0].name_last.value = ...
i call single function event, , let parent both setting cookie , parsing it. way can @ least debug better.
re: div, this:
document.getelementbyid("yourdiv").innerhtml = "your info. is:" + queryarray[0]; document.getelementbyid("yourdiv").style.visibility = 'visible';
but in general it's better use jquery manipulating elements, because mitigates browser differences, though wouldn't matter in case:
$("yourdiv").html("your info. is:" + queryarray[0]); $("yourdiv").css ( { 'visibility': 'visible' } );
good luck.
Comments
Post a Comment