Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
hawkes15687yYou get the username and subtext input values outside of the click handler, meaning they get set when the page loads, not when the button is clicked.
Move them inside the function and that part should work fine.
You also need to move the script tag to the end of your body tag, not outside the html tag, HTML does not allow > 1 root element and behavior gets weird if you do.
Don't put the script in the head tag either, or it gets executed at a time where the DOM element you query for its not available yet. -
@CozyPlanes the script has something wrong... You initialize the username & subtext as soon as the page is loaded, way before the user write in the input fields. Then you bind the url (with empty user & subtext) to the button click.
If you move the 3 'var' lines inside the function (just before the 'location.href'), it should work -
@ewpratten it's location.href, I always write location.href = location.href to refresh a webpage
-
Dacexi119967y@calmyourtities @ewpratten isnt window.location.href the most browser compatible solution?
-
@Dacexi i think so too, but not sure
Made this stupid website after first learning html 6 months ago -
@calmyourtities theres no such function, but if you're interested for 534 other methods: http://phpied.com/files/...
-
You end your singletons with />. Which isn't wrong but it's wrong.
This ain't no HTML 4 in your doctype.:D -
omom13597yPeople please! All the Js code most be IN the onclick callback --" or you will load the value at the rendering of the page, not after you have tipped..
Related Rants
Anyone tell me...
what is wrong?
https://gist.github.com/cozyplanes/...
<!DOCTYPE html>
<html>
<body>
<input type="text" id="username" />
<input type="text" id="subtext"/>
<br>
<button type="button" id="create">Create</button>
</body>
</html>
<script type="text/javascript">
var username = document.getElementById("username").value;
var subtext = document.getElementById("subtext").value;
var url = "https://devbanner.center/generate/...;
document.getElementById("create").onclick = function () {
location.href = url;
};
</script>
undefined
devbanner
js
html
banner