myfreeforum.org Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups  Who is OnlineWho is Online   Join! (free) Join! (free)  
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
For an excellent guide to using your myfreeforum forum, you can visit
howtodoit
The howtodoit "readonly" forum provides answers and walkthroughs for all common questions.
  • Welcome
  • Guest


input box help!
Goto page Previous  1, 2
 
Post new topic   Reply to topic    myfreeforum.org Forum Index -> Web page/template Editing
View previous topic :: View next topic  
Author Message
wee2john
Apprentice
Apprentice

Virtual Cash: 1110

Joined: 04 Sep 2007
Posts: 148
Location: Northern Ireland
Add Karma

rated by 2 members
Add Comment
Show Comments

online/offline
PostPosted: Thu Jun 19, 2008 7:56 am    Post subject: Reply with quote

I have a problem here is the code:

Code:
<script type="text/javascript">
function changeingre(num){
for(i=0;i<=3;i++)
document.getElementById("ingredient_"+i).innerText=num+"";
}
</script>
<div class="servings"><input type="text" name="scale" size="1" value="1" />&nbsp;&nbsp;<input type="hidden" name="mid" value="63990" /><input type="button" class="button" value="change servings" onclick=changeingre(num)(document.all('scale').value) /></div>

<div><span id="ingredient_1">1</span>g sugar</div>
<div><span id="ingredient_2">1</span>g flour</div>
<div><span id="ingredient_3">1</span>tbsp butter</div>


This is the only part that the guy doing it doesn't understand.
Everything shows but when you click change servings button it doesn't respond.


_________________
Click Here--> Cook Like a Pro in a Day!!!

Cook Like a Pro
Back to top
View user's profile Private message
wee2john
Apprentice
Apprentice

Virtual Cash: 1110

Joined: 04 Sep 2007
Posts: 148
Location: Northern Ireland
Add Karma

rated by 2 members
Add Comment
Show Comments

online/offline
PostPosted: Sun Jun 22, 2008 3:23 pm    Post subject: Reply with quote

I have the answer for changing the servings with fractions (not deciamls):

The code was:

Spoiler:

Code:
<script type="text/javascript">
var defaultScale = 4;
function changeServe(scale) {
    var Ingredients = document.getElementsByTagName("span");
    for (var i=0; i<Ingredients.length; i++) {
        if (Ingredients[i].className == "ingredients") {
            var _scale = eval(Ingredients[i].innerHTML.replace(" ","+"));
            var _one_scale = _scale / defaultScale;
            var decValue = _one_scale*scale;
            var fracValue = decToFrac(decValue);
            Ingredients[i].innerHTML = fracValue;
        }
    }
    defaultScale = scale;
}
function decToFrac (decValue) {
    var arrVal = String(decValue).split(".");
    if (arrVal.length == 1) {
        return decValue;
    } else {
        var pembilang = 1;
        var penyebut  = parseFloat("0."+arrVal[1]);
        var result = 0;
        for(;;) {
            if ((pembilang*100000/penyebut) % 2 == 0) {
                result = pembilang+"/"+(String(pembilang*100000/penyebut).replace(/0/g,""));
                if (arrVal[0] != "0") result = arrVal[0] + " " + result;
                break;
            } else {
                pembilang++;
            }
        }                    
    }
    return result;
}

</script>

<form>
<div class="servings">
    <input type="text" name="scale" id="scale" size="1" value="4" />
    <input class="button" id="btnServe" type="button" value="change servings" onclick="changeServe(document.getElementById('scale').value)" />
</div>
</form>
Ingredients:<br/>
<span class="ingredients">1/4</span> cup finely chopped celery<br/>
<span class="ingredients">1/4</span> cup chicken broth<br/>
<span class="ingredients">2</span> pounds ground top sirloin<br/>
<span class="ingredients">1/4</span> cup bread crumbs<br/>
<span class="ingredients">1/2</span> teaspoon Worcestershire sauce<br/>
<span class="ingredients">1/4</span> teaspoon nutmeg
Salt and freshly ground pepper to taste<br/>
<span class="ingredients">3</span> tablespoons butter<br/>


_________________
Click Here--> Cook Like a Pro in a Day!!!

Cook Like a Pro
Back to top
View user's profile Private message
Display posts from previous:   
Post new topic   Reply to topic    myfreeforum.org Forum Index -> Web page/template Editing All times are GMT + 1 Hour
Goto page Previous  1, 2
Page 2 of 2
 
 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Card File  Gallery  Forum Archive
Powered by phpBB © 2001, 2005 phpBB Group
Create your own free forum | Buy a domain to use with your forum