None of these three examples are working, why is the object loosing the string in passing it through the function?
function fillDiv(userOutput, userIntput){
document.getElementById(userOutput) = document.getElementById(userIntput).innerText;
document.getElementById(userOutput) = document.getElementById(userIntput).textContent;
document.getElementById(userOutput) = document.getElementById(userIntput).value;
}
Would appreciate a heads up on what I’m doing wrong with the object. I did try generating it into a variable and then passing it like this:
var userOutputObj = document.getElementById(userOutput).innerText;
userOutputObj.innerHTML = document.getElementById(userInput).value;
But still no joy!
From what I can see, the top three your not setting the innerHTML or innerText.
Might work if it’s
function fillDiv(userOutput, userIntput){
document.getElementById(userOutput).innerHTML = document.getElementById(userIntput).innerText;
document.getElementById(userOutput).innerHTML = document.getElementById(userIntput).textContent;
document.getElementById(userOutput).innerHTML = document.getElementById(userIntput).value;
}
And the bottom two lines your trying to set the .innerHTML or a .innerText which won’t work, your userOuputObj is a string not an object.
This might work:
var userOutputObj = document.getElementById(userOutput);
userOutputObj.innerHTML = document.getElementById(userInput).value;
Ok I’ve just figured out that omitting the .innerHTML returns the ID tag name for the div passed into the function. The only bit that I don’t get is the diffrerence between .value and .innerHTML.
And when I try and pass a null or " " value to the <div id=‘etc’> it kills my code.
All your help is much appreciated by the way, it’s got to the point where I’ve spent too many days fixing this and I’ll admit help is needed now!
.value is referencing a form input, innerHTML is an object property that either sets or gets the html within a tag. What do you mean it kills your code? You don’t pass .value to a div, you pass it to an input, use .innerHTML to access the content within a div.
Your function shouldn’t work:
function fillDiv(userOutput, userIntput){
document.getElementById(userOutput) = document.getElementById(userIntput).innerText;
document.getElementById(userOutput) = document.getElementById(userIntput).textContent;
document.getElementById(userOutput) = document.getElementById(userIntput).value;
}
because you are trying to assign a property as an object. obj = obj works, obj.property = obj.property works, but obj = obj.property will not work.
Also, it could have something to do with you referencing userIntput, and not userInput.
Both these functions kill the document after running them, there’s a problem passing the data to the array or something?
function addNote(userInput){
var userInputObj = document.getElementById(userInput).innerHTML;
if(userInputObj!=null || userInputObj!=""){
noteArray.push(userInputObj);
fillDiv(“notesInfo”, “You added a note. There are now “+noteArray.length+” notes.”);
dispNotes();
dispBtns();
currentChoice = null;
}else{
fillDiv(“notesInfo”, “Please enter text into the box.”);
}
}
function updateNote(currentChoice, userInput){
if(currentChoice!=null){
var oldString = noteArray[currentChoice];
var userInputObj = document.getElementById(userInput).innerText;
noteArray[currentChoice] = userInputObj;
fillDiv(“notesInfo”, “You have updated note “+currentChoice+”.<br />From original: “+oldString+”.”);
//document.getElementById(‘notesInput’).innerHTML = “”;
dispNotes();
dispBtns();
currentChoice = null;
}else{
fillDiv(“notesInfo”, “Please choose a note to update first!”);
}
}
yeah I noticed the spelling error, that was me being too tired and changing it late last night by accident!
I’ll have a mess with it when I get back later, it’s working in the current code. But won’t initialize a second time, so it’s not really working in reality!
function fillDiv(userOutput, userInput){
var userOutputObj = document.getElementById(userOutput);
userOutputObj.innerHTML = userInput;
}
Where is it dying? Try using alerts throughout the processing of your function to see where it stops.
function addNote(userInput)
{
alert(userInput);
var userInputObj = document.getElementById(userInput).innerHTML;
alert(userInputObj);
if(userInputObj!=null || userInputObj!=""){
noteArray.push(userInputObj);
fillDiv("notesInfo", "You added a note. There are now "+noteArray.length+" notes.");
dispNotes();
dispBtns();
currentChoice = null;
}else{
fillDiv("notesInfo", "Please enter text into the box.");
}
}
function updateNote(currentChoice, userInput){
if(currentChoice!=null){
var oldString = noteArray[currentChoice];
var userInputObj = document.getElementById(userInput).innerText;
noteArray[currentChoice] = userInputObj;
fillDiv("notesInfo", "You have updated note "+currentChoice+".<br />From original: "+oldString+".");
//document.getElementById('notesInput').innerHTML = "";
dispNotes();
dispBtns();
currentChoice = null;
}else{
fillDiv("notesInfo", "Please choose a note to update first!");
}
}
Try changing your fillDiv function to this:
function fillDiv(userOutput, userIntput)
{
document.getElementById(userOutput).innerHTML = userInput;
}
Thanks for the heads up, I’ll start using alerts in future. I use trace() a lot in actionscript, so I’m not sure why I didn’t transfer that method to js.
My code’s still dying a bit, but at least it’s cleaner now. I’ll isolate the problem and post it when I find out!
Thanks again 
Firefox won’t take the value, it dies when I’m using the try/catch error checker. Very strange, I’ve been reading around and apparently firefox dismisses innerHTML as a rule for filling the value of a div, where IE changes it to whatever the current value is. Something RTFM on I guess!
Thanks for your help I think I know where to go with it now at least, I’m going to get the browser to check what version it is then change the code accordingly.
Glad to be of some help. Just to clarify, textarea is an input, therefore .value is what you use to attain the text inside of it. innerHTML is used for a non-input (X)HTML node.
This is actually not the case, here is a proof of concept:
<html>
<head>
<title>innerHTML</title>
<style type="text/css">body,html{font-family:Tahoma;font-size:.89em;}</style>
<script type="text/javascript">
var txt,div,lbl;
window.onload = function()
{
txt = document.getElementById('txt');
div = document.getElementById('mydiv');
lbl = document.getElementById('lbl');
}
function swap()
{
try{
div.innerHTML = txt.value;
txt.innerHTML = "";
lbl.innerHTML = "Thanks for typing some carp, yo!";
}catch(e){
alert(e);
}
}
</script>
</head>
<body>
<div id="mydiv">Here is my initial content.</div>
<label for="txt" id="lbl">Please fill in some info:</label><br /><br />
<textarea name="txt" id="txt" cols="20" rows="20"></textarea>
<input type="button" onclick="swap();" value="Insert Values" />
</body>
</html>
Try inputting plaintext or html.
I think that’s the most comprehensive explanation I’ve ever received on a forum, thanks that makes it a hell of a lot clearer.
I’ll go tinker now, but one last question before I do! Why is it necessary to declare the variables in the window.onload function(){etc}, Was this why the code was dying in firefox previously?
[quote=Ubermeowmix;2348991]I think that’s the most comprehensive explanation I’ve ever received on a forum, thanks that makes it a hell of a lot clearer.[/quote] Glad I could help clear things up a bit! 
Why is it necessary to declare the variables in the window.onload function(){etc}, Was this why the code was dying in firefox previously?
Could be why. The reason is that pages load top down, and when you Javascript is done loading (and processing the items that are not within functions) your divs (and everything else beneath your script tags) haven’t loaded yet, so you are assigning your variables a reference to an object that doesn’t technically exist yet. Does that make sense?
var id = document.getElementById("item_that_doesn't_exist_in_the_dom_yet");//equivalent to null
Take note that I am instantiating the variables outside of the function call so that you have access to them outside of the onload function, if you didn’t know, declaring a variable within a function limits it to being accessed only within that function. Assigning these variables in the onload event means that the divs (and everything else) have all been loaded and can now be accessed by the script.
Let me know if you have more questions.
I understand variable scope, but there are still rules that keep popping up here and there. I’ve been working on actionscript and c# at the same time as PHP and SQL. And I’ve only just moved in to javascript, so i’m still settling into the style of it if you catch my drift.
There’s a hell of a lot I don’t know methods and practices, so I’m still hitting barriers like a drunk at a music festival! I’ve managed to create mysefl a development BLOG that has databases for each little project I’m working on so I can keep track of what I’ve done and how I did it.
Thanks for all your help, I’ve got sometihing to chew on for the weekend now.
[quote=Ubermeowmix;2349408]so I’m still hitting barriers like a drunk at a music festival! [/quote]:lol:
No problem, glad I could help! Good luck in your learning of the js.
I suggest you check out http://quirksmode.org/resources.html , a lot of great stuff there!