Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

add input boxes and alerts to this script?

Status
Not open for further replies.

cbsarge

IS-IT--Management
Jun 20, 2001
219
US
I'm trying to add input boxes so that when this is used people can put in values and then alerts when the script is run based on the results. The script was provided by another user who is difficult to reach to help modify this script. I would like the variables A2 and B2 to be the values input by a user. My feeble attempt at making this do what I want is below the other users example.

Code:
// JavaScript Example

var answer; // float, make sure to round to 4 decimal places
if(A2<B2) // most likely losing the attack/agility roll
{ 
if(A2<B2/3)
{answer = 0.0000; }
else
{answer = ((1/2*((1.5*A2)-(0.5*B2)+1)^2)/((A2+1)*(B2+1))); }
}

else

{ // most likely winning the attack/agility roll
if(A2>B2*3)
{answer = 1.0000;}
else // includes ties
{answer = 1-((1/2*((1.5*B2)-(0.5*A2)+1)^2)/((A2+1)*(B2+1))); }
}

My non-working example from
Code:
<script type="text/javascript">
function strTheRoll()
// if(strYOU<strOP) // most likely losing the attack/agility roll
{
{ 
var answer=""; // float, make sure to round to 4 decimal places
if(strYOU<strOP/3)
{
answer = 0.0000;
alert("the answer is "+answer); 
}
else
{
answer = ((1/2*((1.5*strYOU)-(0.5*strOP)+1)^2)/((strYOU+1)*(strOP+1)));}
alert("the answer is "+answer);
}
else
{ // most likely winning the attack/agility roll
if(strYOU>strOP*3)
{
answer = 1.0000;}
alert("the answer is "+answer);
}
else // includes ties
{
answer = 1-((1/2*((1.5*strOP)-(0.5*strYOU)+1)^2)/((strYOU+1)*(strOP+1))); 
alert("the answer is "+answer);
}
}
</script>
 
You have a few errors in tpour code which would prevent it from running:

You have an else statement there that has no If statement to go to because you have it commented out. That would cause errors, and stop the execution of the javascript. The commenting out of the If statement also leaves you with opened braces that do nothing but cause errors.

I suggest you check the error console for whatever browser you are using to debug your code.

You are already getting the values for your textboxes in the strOP and formOp functions by using the getElementByID, use that in your other function instead. I would also remove the running of those functions since they serve no real purpose.



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
I started over and the script now runs and produces a result. I'm not sure what to do with the result yet but, it at least seems to be working.

Thank you vacunita for you help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top