Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Basic Javascript Cookie Personalisation

Featured Replies

Hello,

I'm trying to use a form which allows a user to enter their name. This is then stored in a cookie and used to personalise the page by showing their name. I can't get the code to work though as when I click getCookie() the value isn't showing up. :aggressive: I'm just trying to get the cookie to show in an alert box for now then I'll try and get to print straight onto the page. Actually what would be the best way to do that? I dont think you can print stuff to form labels so it shows in a transparent box? Anyway heres the code I have so far and javascripts arent disabled on firefox:

 

<script type="text/javascript">
 function setcookie()
 {
var the_cookie = escape(custLogin.value);
document.cookie = the_cookie;
alert("cookie set: " + the_cookie);
 }  

 function getcookie()
 {
var cook=document.cookie;
alert("cookie got: "+cook);
 }

</script>

 

 

<div id = "login" class = "login">
<form action = "" method = "">
<h3><label> Customer Login</label></h3>
<label class = "label" id = "label">  Name: </label><input name="custLogin" type = "text" id="custLogin"  size = "16" maxlength = "30"/><br/>
<input name = "Submit" type = "submit" value = "Submit" class = "submit" id = "submit" onclick="setcookie()"/>
</form>
</div>

 

<button onclick= "getcookie()">Get cookie</button>

 

 

Thanks!

Should have posted the URL

 

Its something to do with firefox. It works in IE6. Javascript isnt disabled in FF though.

IE6 imports all ID'd elements to the global namespace. What this means is that you can access the login field from anywhere in your JavaScript by using the variable custLogin. Standards-conforming browsers don't do that.

 

What you want to do is:

custLogin = document.getElementById('custLogin')

 

Also, cookies have a specific syntax. You'll probably want to grab a function for setting and reading cookies - from here for example - to make sure they're stored properly.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.