Get innerHTML from inputText


(theron_hp) #1

Hi Everyone

I have an exercise where I need a user to create a rhyme with specific starting letters. If the starting letters are correct in the inputText boxes, I want to execute something and if not, something else.

Besides checking whether the first letters are correct, I also want to print the words from the textBoxes into a messageBox.

I can check if they are correct, but don’t know how to retrieve the actual completed text words and print them in my messageBox. My attempt lacks insight.

I adjusted a symbol posted by @DBear previously.
innerRecord.zip (31.8 KB)


(Mark Hunte) #2

You want…

var inputText = document.getElementById('myTextarea1').value; // string
    	var inputText2 = document.getElementById('myTextarea2').value;  // string
    	
    	var messageBox = document.getElementById('messageBox1');
    	 
     
    	
    	if ((inputText.charAt(0) == 'a') && (inputText2.charAt(0) == 'b')) {
     
    		messageBox.innerHTML = (inputText +  inputText2   ); // string + string
    	//                        
    	
    	} else {
    	
    		messageBox.innerHTML = "Sorry, the first letters of your rhyme do not match the series";
    	}

(theron_hp) #3

Thanks @MarkHunte. I appreciate your answer. It is what I needed.

Using what you gave, I could work out how to add a space in-between the words as well. Which is a small victory for me.

Thanks again.