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!

textbox evaluate (math) on load

Status
Not open for further replies.

mjpearson

Technical User
Dec 13, 2002
196
US
I've inserted a textbox into my page and I want the text box to be preloaded with the results of a math equation. I tried the EVAL function but that didn't work.

<input type="text" name="S400" size="10" value=eval(25/10)>

Is this even possible? What is the proper syntax?


thanks,



mike
 
But what you want is this (should work, I think)

<input type="text" name="S400" size="10" value="" onload="this.value = eval(25/10)">

If the onload doesn't work, put it in the body onload tag.

--Chessbot

"So it goes."
Kurt Vonnegut, Slaughterhouse Five
 

I'm trying to be tricky....I have a device that provides hosting but only for very limited features. It is a real-time device that databases information so the numbers will change but the server isn't smart enough to do scripting so I have to do it in the client page.

As noted, the 25 is embedded in the page when it is sent to the client. I insert the string <--DATA 20,-1,1,%d --> and that will insert the 20th integer into the page in decimal format.

So, in reality, the line is supposed to look like this:


<input type="text" name="S400" size="10" value=eval(<--DATA 20,-1,1,%d --> / 10)>


 
Here is your page:

Code:
<html>
<head>
<title>Eval</title>
<script type="text/javascript">
<!-- hide

function init()
{
  // repeat for each element you need
  document.forms['a'].elements['S400'].value = <--DATA 20,-1,1,%d -->/10;
}

// end hide -->
</script>
</head>
<body onload="init();">
<form name="a">
<input type="text" name="S400" size="10" value="Error">
</form>
</body>
</html>

Initial value is "error" because if they see the value then your code has failed to execute for some reason.

--Chessbot

"So it goes."
Kurt Vonnegut, Slaughterhouse Five
 
Perfect. That works great.

I had tried onLoad earlier but it didn't work. I figured the onLoad was called before the forms had arrived. Now I understand the the page fully loads before running the onLoad function. My earlier attempt might have been caused by my oversight in not including the ";" at end of my onLoad statement?

Thanks again,


mike
 
The semicolon is only necessary to separate multiple functions in a row; it is not necessary for the last one.

--Chessbot

"So it goes."
Kurt Vonnegut, Slaughterhouse Five
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top