I’m trying to have different html buttons that send user’s to different sections of their profile (social, news, email, etc.) So I made a simple JS function which I linked into the html. Basically when a user clicks a button, it should append the current URL with a string and then visit that URL. On click, however, nothing happens:
profile.html
<head>
<title>Profile</title>
</head>
<script type="text/javascript" src="profile.js"></script>
<body>
<h1 align=center>Welcome to your OmniCloud Profile</h1>
<h2 align=center>Access your content below</h2>
<button name='email' onclick='gotoPage("email")'>Email</button> <br/>
<button name='social' onclick='gotoPage("social")'>Social</button> <br/>
<button name='news' onclick='gotoPage("news")'>News Feeds</button> <br/>
<button name='media' onclick='gotoPage("media")'>Media</button> <br/>
</body>
And here is the JS script
function gotoPage(var url) {
var newurl = document.write(location.href)
newurl += url
window.location.assign(newurl)
}
I’m using Django, so if there is a better way to handle this (perhaps using urls.py, feel free to include that!
When defining a variable in the formal parameters of a function,
varmust be omitted. Also, to declare a variable, you should not usedocument.write(variablevalue). Changing the current location can be achieved by setting a new value to thelocation.hrefproperty.I recommend to have a look at MDN: JavaScript guide.