0

I am using javascript and the parse API and i have this code

<script type="text/javascript">
Parse.initialize("APPID", "JAVASCRIPTCODE");
var currentUser = Parse.User.current().get("FirstName");
document.getElementById("fname").value = currentUser;
</script>

<input type=text id="fname" />

however the code is not adding the data from javascript to the text box where am i going wrong.

1 Answer 1

1

The problem is that you're accessing the element before it is added into DOM.

You can wrap the last statement in DOMContentLoaded

The DOMContentLoaded event is fired when the document has been completely loaded and parsed, without waiting for stylesheets, images, and subframes to finish loading (the load event can be used to detect a fully-loaded page).

document.addEventListener("DOMContentLoaded", function(event) {
    document.getElementById("fname").value = fname;
});

Or, you can also move your <script> at the end of <body> tag.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.