2 Replies - 530 Views - Last Post: 10 February 2013 - 09:26 PM

#1 Eadmanday  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 49
  • Joined: 23-October 12

drop down delimiter not working with .toLowerCase()

Posted 10 February 2013 - 08:34 PM

Ok so i have this much of the code working. and it all works except for my if statment for the toLowerCase method. Am i missing something here? not quite sure why it wont work but that is what learning is.

here is my code for Javascript.

window.onload = function()  { 
document.getElementById("change").onclick = function () {
    var paragraph = document.getElementById('box').value;
    var x = document.getElementById("changeCase");
    var getInfo = document.getElementById('ParaWrite');
    var LowerCase = " ";
	var LowerCase2 = " ";
    var splitAT = " ";
    var options = document.getElementById("split").value;
    alert("above the for loop");

    if (x.checked === true)
	{
        LowerCase = paragraph.toLowerCase();
    } 
	else 
	{
        LowerCase = paragraph;
    }

    for (var i = 0; i < document.form1.split.options.length; i++)
	{
        if (document.form1.split.options[i].selected === true)
		{
            splitAT = paragraph.split(options);
			alert("splitAT[" + i + "]=" + splitAT[i]);
	
        }
    }
	console.log(document.form1.split.options);
    document.write(splitAT +" " +splitAT.length);
}





HTML code
<!doctype html>
<html>
<head>
  <meta charset="utf-8">

  <title>Paragraph</title>
  
  <link rel="stylesheet" href="normalize.css">
  <link rel="stylesheet" href="Textbox.css">
    
</head>

<body>
<h1>Please enter some Text</h1>
<form name="form1" id="form1">

<textarea type="text" id="box" value=""/></textarea>
<label for="write">Case Sensitive checkbox</label>
<input type='checkbox' name='write' id='changeCase' value='Check'/><br>

<input  type='button' value="Count" id="change"/>
<select name="split" id="split">
			<option value="like">like</option>
			<option value="monkey">monkey</option>
			<option value="I">I</option>
			<option value=".">.</>/option>
			<option value=",">,</option>
			<option value="?">?</option>
			<option value=" ">[Space]</option>
		</select>    
</form>
<div id="ParaWrite">
</div>
<script type="text/javascript" src="die.js"></script>
</body>
</html>


This post has been edited by Eadmanday: 10 February 2013 - 08:34 PM


Is This A Good Question/Topic? 0
  • +

Replies To: drop down delimiter not working with .toLowerCase()

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4404
  • View blog
  • Posts: 12,260
  • Joined: 18-April 07

Re: drop down delimiter not working with .toLowerCase()

Posted 10 February 2013 - 09:20 PM

Well first of all there is a missing closing brace at the end of your code there. I am not sure if that just got cut off when you posted here but it is missing.

Second the if statement is working but you set it to a variable LowerCase and then you do nothing with it. It just gets set and then forgotten. Perhaps you should do something with the LowerCase variable.

Other than that, nothing else is wrong. :)
Was This Post Helpful? 0
  • +
  • -

#3 Eadmanday  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 49
  • Joined: 23-October 12

Re: drop down delimiter not working with .toLowerCase()

Posted 10 February 2013 - 09:26 PM

Ya i did forget the braces. Ok. i will try to fix that. if not i will be back ;)/>


edit::

got it to work. put the for loop within the if statement

    if (x.checked === true)
	{
        LowerCase = paragraph.toLowerCase();
	for (var i = 0; i < document.form1.split.options.length; i++)
		{
        if (document.form1.split.options[i].selected === true)
			{
            splitAT = LowerCase.split(options);
			alert("splitAT[" + i + "]=" + splitAT[i]);
			}
		}		
    } 
	else 
	{
        LowerCase = paragraph;
       for (var i = 0; i < document.form1.split.options.length; i++)
		{
        if (document.form1.split.options[i].selected === true)
			{
            splitAT = paragraph.split(options);
			alert("splitAT[" + i + "]=" + splitAT[i]);
	
			}
		}

   }


This post has been edited by Eadmanday: 10 February 2013 - 09:39 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1