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


Javascript post help

 
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: Sat Jun 28, 2008 12:29 pm    Post subject: Javascript post help Reply with quote

I have a javascript for changing the servings of recipes. It is a javascript so when I want to post it I use the html bit in WYSIWYG. But when posted in there the post just comes up as html coding (html of my profile and forum are allowed). Is there anyway to use this javascript on a post so the person viewing the post can change the servings. An example code is:

Code:
<script type="text/javascript">
var defaultScale = 6;
var ingredDefaultValue = [];
var firstRun = true;
function resetIngerdients() {
    var Ingredients = document.getElementsByTagName("span");    
    var j=0;
    if (firstRun) {
        for (var i=0; i<Ingredients.length; i++) {
            if (Ingredients[i].className == "ingredients") {
                ingredDefaultValue[j] = Ingredients[i].innerHTML;
                j++;
            }
        }
        firstRun = false;
    } else {
        for (var i=0; i<Ingredients.length; i++) {
            if (Ingredients[i].className == "ingredients") {
                Ingredients[i].innerHTML = ingredDefaultValue[j];
                j++;
            }
        }
    }
}
function changeServe(scale) {
    resetIngerdients();
    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;
        }
    }
}
function decToFrac (decValue) {
    var arrVal = String(decValue).split(".");
    if (arrVal.length == 1) {
        return decValue;
    } else {
        var pembilang = parseFloat("0."+arrVal[1])*100;
        var penyebut  = 100;
        
        var hasMetModulus = false;
        for (var y=1; y<=10; y++) {
            for (var p=1; p<=10; p++) {
                if (pembilang % p == 0) {
                    pembilang = pembilang / p;
                    penyebut  = penyebut / p;
            hasMetModulus = true;    
                }
            }
        }
        
    if (hasMetModulus) {
            result = Math.round(pembilang) + "/" + Math.round(penyebut);          
            if (arrVal[0] != "0") result = arrVal[0] + " " + result;    
        } else {
        if (String(Math.round(decValue)).length > 1) {
                    result = Math.round(Math.round(decValue)/10);
                       result = result * 10;
        } else {
              result = Math.round(decValue);
        }
        }          
    }
    return result;
}
function resetServe(){
    document.getElementById("scale").value = defaultScale;
    resetIngerdients();
}
</script>
<form>
    <div class="servings">
    <input type="text" value="6" size="1" id="scale" name="scale" />    
    <input type="button" onclick="changeServe(document.getElementById('scale').value)" value="Change Servings" id="btnServe" class="button" />
    <input type="button" onclick="resetServe()" value="Reset"/>
    </div>
</form>
<br/>
<p><u><b>Ingredients:</b></u><br/>
<b>Panna Cotta:</b><br/>
<span class="ingredients">500</span>ml double cream <br />
<span class="ingredients">300</span>g white chocolate <br />
<span class="ingredients">100</span>g sugar<br />
<span class="ingredients">3</span> gelatin leaves, soaked in water<br />
<b>Strawberry Mousse:</b><br/>
<span class="ingredients">800</span>g strawberries, hulled<br />
<span class="ingredients">400</span>ml double cream <br />
<span class="ingredients">8</span> egg whites<br/>
<span class="ingredients">200</span>g sugar<br/>
<span class="ingredients">2</span> sachets powdered gelatin, dissolved in hot water<br/>
<span class="ingredients">200</span>ml hot water</p>
<br/>
<u><b>Method:</b></u><br/>
<b>White Chocolate Panna Cotta:</b>
<br/>1.Over a medium heat, stirring occasionally, hea the cream, chocolate and sugar until chocolate has melted and sugar has dissolved.<br/>

<br/>2. Soak gelatin in <span class="ingredients">100</span>ml hot water and pour into the cream mixture.

<br/>3. Fill some nice glasses half way up with panna cotta mixture. Place in the fridge for at least 3 hours to set.<br/>

<b>Strawberry Mousse:</b>
<br/>1. Purée the strawberries in a liquidiser.<br/>

<br/>2. Whip the cream until thick and fold into the purée a bit at a time.<br/>

<br/>3. Whisk the egg whites until they form soft peaks. Continue to whisk adding sugar gradually until they are glossy and are in stiff peaks.<br/>

<br/>4. Dissolve the powdered gelatin in <span class="ingredients">200</span>ml hot water, stirring continuously until all of it has dissolved.<br/>

<br/>5. Fold the whites into the strawberry cream and then add the gelatin water.<br/>

<br/>6. Use a piping bag to put the mousse on top of the SET panna cotta. Leave ot set for 1½ hours.<br/>



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

Cook Like a Pro
Back to top
View user's profile Private message
admin (no pm's please)
Site Admin
Site Admin

Virtual Cash: 42920

Joined: 22 May 2005
Posts: 19349

Add Karma

rated by 157 members
Add Comment
Show Comments

online/offline
PostPosted: Sat Jun 28, 2008 1:31 pm    Post subject: Reply with quote

No way. If you let javascript in posts it would be a security issue.
_________________

Family Friendly Shareware | | Web Design/Services | Free Forums

forum.myfreeforum.org
Back to top
View user's profile Private message Send e-mail Visit poster's website
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 29, 2008 8:55 am    Post subject: Reply with quote

oh right thanx anyway
_________________
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
Page 1 of 1
 
 
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