|
|
| View previous topic :: View next topic |
| Author |
Message |
wee2john Apprentice

Virtual Cash: 1110
Joined: 04 Sep 2007 Posts: 148 Location: Northern Ireland Add Karma
 rated by 2 members
Add Comment
Show Comments
 |
Posted: Sat Jun 28, 2008 12:29 pm Post subject: Javascript post help |
|
|
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 |
|
 |
admin (no pm's please) Site Admin

 Virtual Cash: 42920
Joined: 22 May 2005 Posts: 19349
Add Karma
 rated by 157 members
Add Comment
Show Comments
 |
|
| Back to top |
|
 |
wee2john Apprentice

Virtual Cash: 1110
Joined: 04 Sep 2007 Posts: 148 Location: Northern Ireland Add Karma
 rated by 2 members
Add Comment
Show Comments
 |
|
| Back to top |
|
 |
|
|
|
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
|
|