CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   JavaScript programming (http://www.codingforums.com/forumdisplay.php?f=2)
-   -   Lowercase Output (http://www.codingforums.com/showthread.php?t=270781)

Ilan 08-18-2012 04:10 AM

Lowercase Output
 
Hi,

For my JavaScript at http://www.payitforwardfriends.com/converter.html I want it so that when you press calculate the result is all in lower-case. In other words, I want it to write the substance in lower-case in the result but not in the list of options.

How do I do this?

Thanks!

jmrker 08-18-2012 04:17 AM

See: http://www.webdeveloper.com/forum/sh...d.php?t=263670

Ilan 08-18-2012 04:24 AM

Thanks for your reply but it doesn't seem to work.

low tech 08-18-2012 04:36 AM

Erm

Quote:

I changed it but it doesn't seem to work.
Quote:

Thanks for your reply but it doesn't seem to work.
Then you are doing something wrong because it works for me.

LT

Ilan 08-18-2012 06:50 AM

so you're saying that at http://www.payitforwardfriends.com/converter.html it works right now?

the result text is all in lowercase? for me it's showing up in uppercase (the first letters of each substance word)

Ilan 08-18-2012 09:05 AM

What do you mean?

jmrker 08-18-2012 01:59 PM

Quote:

Originally Posted by Ilan (Post 1261877)
so you're saying that at http://www.payitforwardfriends.com/converter.html it works right now?

the result text is all in lowercase? for me it's showing up in uppercase (the first letters of each substance word)

Show specifically which line in your code you are changing and how.

Are you using the error console?

AndrewGSW 08-18-2012 02:20 PM

You are setting

Code:

var substancetext = "";
and it is never altered to anything else?! So,


Code:

if (substancetext != "") {
    document.getElementById('substancemessage').innerHTML = substancetext.toLowerCase();
}

will never do anything.

Ilan 08-18-2012 08:09 PM

Quote:

Originally Posted by AndrewGSW (Post 1261939)
You are setting

Code:

var substancetext = "";
and it is never altered to anything else?! So,


Code:

if (substancetext != "") {
    document.getElementById('substancemessage').innerHTML = substancetext.toLowerCase();
}

will never do anything.

Then why is there an output at all?

Ilan 08-18-2012 08:11 PM

Quote:

Originally Posted by jmrker (Post 1261936)
Show specifically which line in your code you are changing and how.

Are you using the error console?

I am not using the error console.

Code:

if (substancetext != ""){
                        document.getElementById('substancemessage').innerHTML = substancetext();
                }

was changed to

Code:

if (substancetext != ""){
                        document.getElementById('substancemessage').innerHTML = substancetext.toLowerCase();
                }

like you said.

Aren't we dealing with result and not substancetext?

jmrker 08-19-2012 12:42 AM

You're code is confusing...

If you want 'result' to be the display then you should try...
Code:

  result = result.toLowerCase();
If it is an element called 'result' (a textbox?), then ...
Code:

  document.getElementById('result').value = result.toLowerCase();
Wherever/Whenever your output is to be updated, you will need to use the .toLowerCase() function (if it is changed in several places).

Ilan 08-19-2012 12:57 AM

I'm confused too. Let me try to explain this more clearly:

Alright see the textbox at the bottom that says result? When you select a substance, select a from this and a to this, and press calculate that box is filled.

The substances in the box are capitalized (the first letter of each word). I would like them to be lowercase. Where do I place the necessary code?

jmrker 08-19-2012 01:46 AM

Did you write the code, copy it or have someone else do it for you?

What does this mean to do?
Code:

  var result;
  document.getElementById('result').value = result.toLowerCase();

Not what you think, I am sure.

Ilan 08-19-2012 01:58 AM

I am editing the code someone else wrote and making major changes.

Originally, there was a line of text underneath the "result" that was substancetext. When I got rid of it, for some reason the conversion stopped to work. That's why that line is there. I was told to put the lowercase code there to fix it, and tried it and forgot to remove it. There is no reason why that would work. Substance text is not visible to the user, only result. I will remove it now.

jmrker 08-19-2012 02:23 AM

Still rather confusing but start from here for further discussions ...
Code:

<html>
<head>
<title> Undefined </title>
<script type="text/javascript">

function eval_and_fix(formula){
  var input_number;
  input_number = eval(formula) + '';

  // If scientific notation, return
  if ((input_number.indexOf("e") > -1) || (input_number.indexOf("E") > -1)) { return input_number; }

  // if an integer, return
  if (input_number.indexOf('.') == -1) { return input_number; }

  // Seperate and round to 12
  var first, last, split_at;

  split_at = input_number.indexOf('.');

  first = input_number.substr(0,split_at);

  last = input_number.substr(split_at, input_number.length - split_at);
  //last = Math.round(last * 1000000000000);
  //last /= 1000000000000;
  // round to only 3 instead
  last = Math.round(last * 10000);
  last /= 10000;

  return parseInt(first) + last;
}

function parseinputweight2vol(inputamount, inputdensity) {
  var teststring;
  var density = document.getElementById('density').value;
  var quantity = document.getElementById('quantity').value;

  if ( quantity.length == 0 ) {
        alert ("Please enter the amount you want to convert!");
        return false;
  }
  if ( isNaN(parseFloat(quantity)) ) {
        alert ("The entered amount isn't a number!");
        return false;
  }
  if ( parseFloat(quantity) <= 0 ) {
        alert ("The amount have to be positive!");
        return false;
  }
  if ( density.length == 0 ) {
        alert ("Please enter the density or choose the substance from the list!");
        return false;
  }
  if ( isNaN(parseFloat(density)) ) {
        alert ("The entered density isn't a number!");
        return false;
  }
  if ( parseFloat(density) <= 0 ) {
        alert ("The density have to be positive!");
        return false;
  }
  return true;
}

function calcweight2vol() {
  if ( parseinputweight2vol() == false ) { return false; }

  var inunit = document.getElementById('inunit');
  var inunittext = inunit.options[inunit.selectedIndex].text;
  var inunitval = parseFloat(inunit.value);

  var outunit = document.getElementById('outunit');
  var outunittext = outunit.options[outunit.selectedIndex].text;
  var outunitval = parseFloat(outunit.value);

  var densunit = document.getElementById('densunit');
  var densunittext = densunit.options[densunit.selectedIndex].text;
  var densamount = parseFloat(document.getElementById('density').value);

  var substance = document.getElementById("substance");
  var substanceAsText = substance.options[substance.selectedIndex].text;

  var densvalue = densamount / parseFloat(densunit.value);
  var quantity = parseFloat (document.getElementById('quantity').value);
  var amount = quantity;

  var substancetext = "";

  var result;

// first we convert a given amount of substance to grams
  if ( inunitval > 0 ) { amount = amount * inunitval; }
                  else { amount = amount * (-inunitval) * densvalue; }

// then we convert the grams to given output unit

  if ( outunitval > 0 ) { result = amount / outunitval; }
                  else { result = amount / densvalue / (-outunitval); }
  result = eval_and_fix(result);


    var str  = quantity + " " + inunittext + "s of " + substanceAsText + " = " + result + " " + outunittext + "s of " + substanceAsText;
    document.getElementById('result').value = str.toLowerCase();

/*  something goofy about the following logic that caused the display problem
  if (quantity != "1" && result != "1") {
    document.getElementById('result').value
      = quantity + " " + inunittext + "s of " + substanceAsText + " = " + result + " " + outunittext + "s of " + substanceAsText;
  }
  else {
    if (quantity != "1" && result == "1") {
      document.getElementById('result').value
        = quantity + " " + inunittext + "s of " + substanceAsText + " = " + result + " " + outunittext + " of " + substanceAsText;
    } else {
      if (quantity == "1" && result != "1") {
        document.getElementById('result').value
          = quantity + " " + inunittext + " of " + substanceAsText + " = " + result + " " + outunittext + "s of " + substanceAsText;
      } else {
        document.getElementById('result').value
          = quantity + " " + inunittext + " of " + substanceAsText + " = " + result + " " + outunittext + " of " + substanceAsText;
      }
    }
  }
*/
  if (substancetext != ""){
        document.getElementById('substancemessage').innerHTML = substancetext.toLowerCase();
  }
//  alert(result);
//  document.getElementById('result').value = result.toLowerCase();
}

function copydensity() {
  resetForm();
  if (document.getElementById('substance').selectedIndex == -1) { return; }
  document.getElementById('density').value
    = eval_and_fix(parseFloat(document.getElementById('substance').value) * parseFloat(document.getElementById('densunit').value));
}

function checkcopydensity() {
  if (document.getElementById('substance').selectedIndex == -1) { return; }
  copydensity();
}

function resetdensityForm() {
  document.getElementById('substance').selectedIndex = -1;
  resetForm();
}

function resetForm() {
  document.getElementById('result').value = "";
  document.getElementById('substancemessage').innerHTML = "&nbsp;";
}

</script>
</head>
<body>
<br><center>
<form align="center">
<table>
 <tr>
  <td align="center">Substance</td>
 </tr>
 <tr>
  <td align="center">
  <select id="substance" onchange="copydensity();" size=10>
    <option value="0.508398656">All Purpose Flour</option>
    <option value="0.680251723">Almonds</option>
    <option value="0.817021276">Baking Powder</option>
    <option value="0.508398656">Bread Flour</option>
    <option value="0.766632894">Brown Sugar</option>
    <option value="1.016797312">Butter</option>
    <option value="0.471198754">Cake/Pastry Flour</option>
    <option value="0.64680851">Chocolate Chips</option>
    <option value="0.42931442">Cocoa Powder</option>
    <option value="0.680251723">Corn Meal</option>
    <option value="0.627245095">Corn Starch</option>
    <option value="0.743044189">Dried Currants</option>
    <option value="0.319148936">Flaked Coconut</option>
    <option value="0.902763969">Granulated Sugar</option>
    <option value="0.425531914">Grated Coconut</option>
    <option value="0.851063829">Ground Almonds</option>
    <option value="0.611365472">Hazelnuts</option>
    <option value="1.533265789">Honey</option>
    <option value="0.508398656">Icing Sugar</option>
    <option value="1.446808511">Molasses</option>
    <option value="0.680251723">Peanuts</option>
    <option value="0.480575844">Pecans</option>
    <option value="0.611365472">Pistachios</option>
    <option value="0.508398656">Powdered Sugar</option>
    <option value="0.743044189">Raisins</option>
    <option value="0.407576981">Rolled Oats</option>
    <option value="1.225531915">Salt</option>
    <option value="0.872340425">Shortening</option>
    <option value="0.340425531">Sliced Almonds</option>
    <option value="0.958170212">Sour Cream</option>
    <option value="0.480575844">Walnuts</option>
    <option value="0.542672722">Whole Wheat Flour</option>
  </select>
  </td>
  <td style="display: none;" align="center">
  <INPUT id="density" type="text" value="1" size="12" onFocus="resetdensityForm();"><br>
  <select id="densunit" onchange="checkcopydensity()">
    <option value="240">grams/cup</option>
    <option selected value="1">g/cm³</option>
  </select >
  </td>
 </tr>
 <tr>
  <td colspan="2">Convert what quantity?: <INPUT id="quantity" type="text" value="1" size="7" onFocus="resetForm();"></td>
 </tr>
 <tr>
  <td align="center">From this</td><td align="center">To this</td>
 </tr>
 <tr>
  <td align="center">
  <select id="inunit" size=7 onchange="resetForm();">
    <option value="-240">cup</option>
    <option value="1">gram</option>
    <option value="28">ounce</option>
    <option value="454">pound</option>
    <option value="-15">tablespoon</option>
    <option value="-5">teaspoon</option>
  </select >
  </td>
  <td align="center">
  <select id="outunit" size=7 onchange="resetForm();">
    <option value="-240">cup</option>
    <option value="1">gram</option>
    <option value="28">ounce</option>
    <option value="454">pound</option>
    <option value="-15">tablespoon</option>
    <option value="-5">teaspoon</option>
  </select>
  </td>
 </tr>
 <tr>
  <td colspan="2" align="center">
  <button type="button" OnClick="calcweight2vol()">Calculate</button>
  </td>
 </tr>
 <tr>
  <td colspan="2">Result:<BR>
  <INPUT type="text" size="60" id="result" value="">
  </td>
 </tr>
 <tr>
  <td colspan=2 id="substancemessage">&nbsp;</td>
 </tr>
</table>

</form>
<script type="text/javascript">
 copydensity();
</script>
</body>
</html>



All times are GMT +1. The time now is 02:33 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.