Thread Closed

#1
how do i tell it to use variables as numbers and not letters
<script>
function solv() {
var a = document.getElementById('a').value;
var f = document.getElementById('f').value;
var b = document.getElementById('b').value;
document.getElementById('c').value=(a+f+b);
}
function changevalue() {
var fn = document.getElementById('f').value
if (fn=="*") {document.getElementById('f').value="/"}
else if (fn=="/") {document.getElementById('f').value="+"}
else if (fn=="+") {document.getElementById('f').value="-"}
else if (fn=="-") {document.getElementById('f').value="*"}
}
</script>
<input id="a" type="text" value="1"/>
<input id="f" type="button" value="*" onclick="changevalue()">
<input id="b" type="text" value="2"/>
<input id="e" type="button" value="=" onclick="solv()"> 
<input id="c" type="text"/>
ReportQuote
#2
Google parseint

Have I helped you? Do you like my add-ons?
Would you consider donating to show your appreciation for my efforts?

/images/paypal.png
ReportQuote
#3
that helps thanks
is there a way i an use a variable for an operation (variable f)
edit:
never mind i just thought of a way to do it with out useing a variable for an operation

Edited by az on March 2, 2009, 6:37 a.m.

ReportQuote
#4
Have you ever tried eval() ?

Have I helped you? Do you like my add-ons?
Would you consider donating to show your appreciation for my efforts?

/images/paypal.png
ReportQuote
#5
That works much better than parseint
now decimals work.
I finally figured out the basics of js a few days ago on my own, lol
Needless to say I have been putting it to use.
I don't know all the functions yet.
Math.random() I am good with.
view-source-tab:http://absol.uuuq.com/gtools/tankbrowser.html
I put it to good use.
Here are the changes I made to the code I posted in the 1st place.
<SCRIPT>function solv() {
var fn = document.getElementById('f').value;
var a = document.getElementById('n1').value;
var b = document.getElementById('n2').value;
if (fn=="*") {document.getElementById('x').value=eval(a)*eval(b);}
else if (fn=="/") {document.getElementById('x').value=eval(a)/eval(b);}
else if (fn=="+") {document.getElementById('x').value=eval(a)+eval(b);}
else if (fn=="-") {document.getElementById('x').value=eval(a)-eval(b);}
document.getElementById('x').select();
}
function changevalue() {
var fn = document.getElementById('f').value;
if (fn=="*") {document.getElementById('f').value="/"}
else if (fn=="/") {document.getElementById('f').value="+"}
else if (fn=="+") {document.getElementById('f').value="-"}
else if (fn=="-") {document.getElementById('f').value="*"}
}</SCRIPT>
<TABLE BORDER="0" CELLPADDING="5" style="border:1px solid lightblue;">
<TR>
<TD align="center">Basic Calculator</BR>
<input id="n1" onfocus="this.style.width='100px'" onblur="this.style.width='25px'" onKeyPress="return numbersonly(event, false)" type="text"/>
<input id="f" type="button" class="button" value="*" onclick="changevalue()">
<input id="n2" onfocus="this.style.width='100px'" onblur="this.style.width='25px'" onKeyPress="return numbersonly(event, false)" type="text"/>
<input id="e" type="button" class="button" value="=" onclick="solv()"> 
<input id="x" onKeyPress="return false;" onfocus="this.style.width='100px'" onblur="this.style.width='25px';document.getElementById('n1').value=this.value;document.getElementById('n2').value='';this.value='';document.getElementById('f').focus();" type="text"/></TD>
</TR>
</TABLE>

Had to change some ids they were taken on the page i put it in.
ReportQuote
#6
function solv() {
  var fn = document.getElementById('f').value;
  var a = document.getElementById('n1').value;
  var b = document.getElementById('n2').value;
  document.getElementById('x').value=eval(a+fn+b)
}

That is a little simpler then your solv function. Now go write a Firefox calculator extension :P

Have I helped you? Do you like my add-ons?
Would you consider donating to show your appreciation for my efforts?

/images/paypal.png
ReportQuote
#7
<TABLE id="calculator" align="center" BORDER="0" CELLPADDING="5" style="border:1px solid lightblue;">
<TR>
<TD align="center">Basic Calculator</BR>
<INPUT style="text-align:center" id="calc" onkeyup="this.value=this.value.replace(/[^0-9,+,-,-,*,/,^,(,),.]/g, '');" onkeypress="if(event.keyCode==13) this.value=eval(this.value)" type="text"/>
</TD>
</TR>
<TR>
<TD align="center">
<INPUT type="button" value="Solv It :)" onclick="document.getElementById('calc').value=eval(document.getElementById('calc').value)"/>
</TD>
</TR>
</TABLE>

That look better. :)
BTW: My last post in General has been edited.
(I assume you get email alerts of new post and you do not get them for edits) (Replying to it is a low priority right now.)
ReportQuote
#8
No I don't get alerts for edits, and unless pointed out I would never notice them.

It is possible to do all align="center" BORDER="0" CELLPADDING="5" as values in the style attribute.

Have I helped you? Do you like my add-ons?
Would you consider donating to show your appreciation for my efforts?

/images/paypal.png
ReportQuote
#9
I'm well aware of the awesomeness of css
It is my best area. :) padding:5px;
border:0px;
text-align:center;
Is the way align="center" BORDER="0" CELLPADDING="5" are written in css. just so you know that i know
ReportQuote
#10
:) css will get a lot more awesome when CSS 3 is fully implemented. There is some really great stuff in it.

Have I helped you? Do you like my add-ons?
Would you consider donating to show your appreciation for my efforts?

/images/paypal.png
ReportQuote
#11
Took me all afternoon but I finished the final version.
http://userscripts.org/scripts/show/43584
ReportQuote
#12
well done :) I don't have Grease Monkey so I can't test it right now.

Have I helped you? Do you like my add-ons?
Would you consider donating to show your appreciation for my efforts?

/images/paypal.png
ReportQuote
#13
by any chance is there a way to from a page make a link open in a new tab not a new window or in the current page
<a href="http://codefisher.org" target="_blank">text</a>

or
<a onclick="window.open('http://codefisher.org')">text</a>

is there a way i can have that open in a new tab
not talking about the settings in firefox to do this.
ReportQuote
#14
In extensions yes, in web site code, no. It is up to the user to set how they want the new windows to be handled, you can't force it to happen.

Have I helped you? Do you like my add-ons?
Would you consider donating to show your appreciation for my efforts?

/images/paypal.png
ReportQuote
#15
<input type="text" title="incorrect output" value="6.6+0.6" onkeypress="if (event.which==13){this.value=eval(this.value);return false;}">

Output is off by 0.000000000000001. Why?
ReportQuote
#16
Because you can't represent numbers exactly in binary, any more then you can in decimal. Right out 1/3 exactly in decimal. You can't.

Have I helped you? Do you like my add-ons?
Would you consider donating to show your appreciation for my efforts?

/images/paypal.png
ReportQuote
#17
How long is too long for an array?
I have one that is getting close to 700 values
http://absol.site88.net/js/gtools/tanks.js it is used in 3 pages my local copy has 674 values added over 100 last Saturday needless to say my finger were tired after that
BTW is there a way i can have a php script get the array out of it for a server side process (been using 2 arrays with the same values in different formats (php and js))
ReportQuote
#18
Sorry assignment week, had not checked my email for three days...

There is some maximum size. Probably your computers physical limits, or when it reaches something like 2^32 strange things might happen.

Can't you compute the values with some function? You can use php to create js files if you wanted.

Have I helped you? Do you like my add-ons?
Would you consider donating to show your appreciation for my efforts?

/images/paypal.png
ReportQuote
#19
Can't you compute the values with some function? Sadly no.
do you know of something that can be used to test php file on a windows os? (also making domain relative src attributes work would be great)
src="/js/file.js" does not work very well in windows
2^32=64
i assume you meant 2e32=20000000000000000000000000000000
Edit:
for ( $i = 1; $i < sizeof($ids); $i++) {
echo "\n" . "tanks[x]=" . $ids[$i] . ";x++;";
}

it keeps putting a line break after $ids
how can i tell it not to?
ps yes i know the first value is ids which is not included in the for loop
it is used else where
Edit:
fixed it with substr($ids,0,strlen($ids)-2);
file function kept the enter characters after each line

Edited by az on June 2, 2009, 4:06 a.m.

ReportQuote
#20
On my calculator 2^32 gives 4,294,967,296. 32 bit unsigned int.

I have used http://www.apachefriends.org/en/xampp.html

Rather ugly solution, and will fail if the input file is created with \n (Linux) or \r (mac) for line beaks, instead of \r\n (m$). I would have used preg_replace or similar, but that could be tricky.

Have I helped you? Do you like my add-ons?
Would you consider donating to show your appreciation for my efforts?

/images/paypal.png
ReportQuote

Thread Closed