PDA

View Full Version : Javascript problem please help!


neozbiljno
01-05-2008, 06:04 PM
Hello!

I must appologue in a start of this writing for my english wroten text, its not the best edition that you have been seen, but please have patience for text.

I am having some problems with my own script that am writing for mechanical ingeniring if anybody see a problem in script could you help???!!!

I am doing some script about temperature and materials, how are materials related with changing temperature.
It should be simple scripte where you put in start lenght of some material and start temperature and temperature to be heated material.
materials are choising with radiobutton and every material have unique number.
now in here is the problem script is not worjing and it dont wont to write result in inputbox.
can anybody help me please!!! :confused::confused::confused:

here is script:
<html>
<head>
<title>Iz knjige</title>

<body background="wood.png">

<script language="JavaScript">
var K=273;
var m;
var Lz, Tz, Tk;

function izracun(Lk) {

Lz=parseFloat(document.vnos.this.value.Lz);
Tz=parseFloat(document.vnos.this.value.Tz);
Tk=parseFloat(document.vnos.this.value.Tk);



if(form.material[0].checked){
m=0.0000238;
}
if(form.material[1].checked){
m=0.0000165;
}
if(form.material[2].checked){
m=0.0000165;
}

Lk=(Lz*(1+m*((K+Tk)-(K+Tz))));

document.write(Lk)

}
</script>
</head>
<body>

Zacetna dolzina: <input type="text" name="Lz" onBlur="Lz=parseFloat(this.value)" size="7" value=""> [mm]<BR>
Zacetna temperatura: <input type="text" name="Tz" onBlur="Tz=parseFloat(this.value)" size="7" value="20"> [°C]<BR>
Koncna temperatura: <input type="text" name="Tk" onBlur="Tk=parseFloat(this.value)" size="7" value=""> [°C]<BR>

Material:<br>
<input type="radio" name="material">aluminij (Al)<BR>
<input type="radio" name="material">baker (Cu)<BR>
<input type="radio" name="material">cink (Zn)<BR>

</table></center><P><center><input type="button" name="izracun" value="Izracun" onClick="izracun(Lk.value*1.0, material)"><br><br>



<B>Koncna dolzina=<INPUT type="text" name="Lk", size=5>[mm]</B><BR>

</body>
</html>

A1ien51
01-07-2008, 05:20 AM
Basic example



<html>
<head>
<script type="text/javascript">
function calc(){
var a = parseFloat(document.forms[0].t1.value);
var b = parseFloat(document.forms[0].t2.value);

if(document.forms[0].r1[0].checked){
alert(document.forms[0].r1[0].value);
}
else if(document.forms[0].r1[1].checked){
alert(document.forms[0].r1[1].value);
}
else{
alert("None selected");
}

document.forms[0].t3.value = a + b;

}
</script>
</head>
<body>
<form id="form1">
<input type="text" name="t1" />
+ <input type="text" name="t2" />
= <input type="text" name="t3" readOnly="true"/><br/>
<input type="radio" name="r1" value="foo" />foo
<input type="radio" name="r1" value="bar" />bar
<input type="button" name="b1" onclick="calc()" value="Add" />
</form>
</body>
</html>



Hopefully you can change it to make it work for your needs.

Eric

neozbiljno
01-07-2008, 02:43 PM
Thank you for helping me (I realy need help in javascript), but there is still one problem left:
Radio button must stand there for a material and that material have some number that has to be included in calculation or function.
In your script when add button is clicked alert box show up with the radiobuttons value, thats not what i had in my minds, radiobutton is there that user can pick which material (number) to choise for equation.

Lk=(Lz*(1+m*((K+Tk)-(K+Tz))))

Lk...that is result that has to be writen in a box
Lz...is the number to wrote in a box
1...is number 1
m...stands for some number of material which we choise from radiobuttons
K...273 temperature from °C to Kelvin
Tk...is the number to wrote in a box
Tz...is the number to wrote in a box

I will try to do this with script that you wrote.

thanks again, and if you see another answer here please write it.

bye

A1ien51
01-07-2008, 03:31 PM
I did not want to give you the exact answer. You already were doing the basic idea in your orginal code you posted when you stuck the value into the variable m.

You need to do the same thing and run your calculation.

Eric

neozbiljno
01-07-2008, 07:32 PM
Ok thats done, finish. your script helped me i had mixed my and yours and it works.
Now there is only one problem left and that is much harder that this one before. When program (javascript) do the equation it has to draw first lenght that we put in, in the start of program and draw the finish lenght of the material, if you understand me.

I will first do that script and if that dont work i will ask for help here.

thanks again.

bye

A1ien51
01-07-2008, 07:37 PM
well you can add to divs to the page

<div id="div1" style="border:1px solid black;background-color:blue;overflow:hidden">before</div>
<div id="div2" style="border:1px solid black;background-color:blue;overflow:hidden">after</div>

and set their widths

document.getElementById("div1").style.width = "123" + "px";
document.getElementById("div2").style.width = "156" + "px";

JavaScript does not have a drawing api so you are limited on graphics.

Eric