Please post a link to the page on your site that contains the problematic script so we can check it out.
I'm sorry, I was confused. I thought this was a PHP error - can you paste line 31 here and provide a link to your page?
Please post a link to the page on your site that contains the problematic script so we can check it out.
I'm sorry, I was confused. I thought this was a PHP error - can you paste line 31 here and provide a link to your page?
Jeremy | jfein.net
In the code:
how can i used it in php and also the onkeyenter because in my real webpage my code for input type is like this:Code:<html> <head> <script type="text/javascript"> var subtract = function(c, b, output){ output.value = c.value-b.value; } </script> <input type="text" id="c" value="0"/>-<input type="text" id="b" value="0"/>=<input type="text" id="a" value="0"/><br/> <input type="text" id="d" value="0" /> <script type="text/javascript"> document.getElementById('c').onmousedown = function(){ subtract(document.getElementById('c'), document.getElementById('b'), document.getElementById('a'), document.getElementById('d')); } document.getElementById('b').onmousedown = function(){ subtract(document.getElementById('c'), document.getElementById('b'), document.getElementById('a'), document.getElementById('d')); } </script> </head> </html>
PHP Code:echo "\n\t\t<td><input size='6' type='text' name='inqty[]' id='inqty" . $ctr . "' onkeypress='return handleEnter(event,\"outqty" . $ctr . "\");' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='outqty[]' id='outqty" . $ctr . "' onkeypress='return handleEnter(event,\"idno" . $ctr . "\");' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='varqty[]' id='varqty" . $ctr . "' onkeypress='return handleEnter(event,\"varsublot" . $ctr . "\");' /></td>";
and i have this code:
</style>
<script language="javascript">
function handleEnter(e, nextfield)
{
var characterCode = (e && e.which)? e.which: e.keyCode;
if(characterCode == 13)
{
document.getElementById(nextfield).focus();
return false;
}
else
{
return true;
}
}
</script>
Last edited by rhodarose; 12-10-2010 at 02:56 AM.
my webpage was on localhost
I'm sorry, because I'm not good in codeing and analyzing..I really need to fix this problem..
Thank you
Give the ids of c, b, and a to the right ones (c = first number, b = second, a = result, because c-b=a, and a+b=c)
Jeremy | jfein.net
You mean it should be like this
It is onmousedown , I want it press enter.Code:echo "\n\t\t<td><input size='6' type='text' name='inqty[]' id='a" . $ctr . "' onkeypress='return handleEnter(event,\"b" . $ctr . "\");' /></td>"; echo "\n\t\t<td><input size='6' type='text' name='outqty[]' id='b" . $ctr . "' onkeypress='return handleEnter(event,\"idno" . $ctr . "\");' /></td>"; echo "\n\t\t<td><input size='6' type='text' name='varqty[]' id='c" . $ctr . "' onkeypress='return handleEnter(event,\"varsublot" . $ctr . "\");' /></td>"; how about this code: <script type="text/javascript"> document.getElementById('c').onmousedown = function(){ subtract(document.getElementById('c'), document.getElementById('b'), document.getElementById('a'), document.getElementById('d')); } document.getElementById('b').onmousedown = function(){ subtract(document.getElementById('c'), document.getElementById('b'), document.getElementById('a'), document.getElementById('d')); } </script>
Honestly, I don't know where i can put the code you suggeted. I really need to fix this problem, i don't know why, I'm sorry I'm not good in coding and analyzing.
I only want is the input and output should be subtract and the result would appear in varqty text field. when they press enter key.
Thank you
It should be like this:
Tell me if that works, then I'll do the enter.Code:echo "\n\t\t<td><input size='6' type='text' name='inqty[]' id='c" . $ctr . "' onkeypress='return handleEnter(event,\"b" . $ctr . "\");' /></td>"; echo "\n\t\t<td><input size='6' type='text' name='outqty[]' id='b" . $ctr . "' onkeypress='return handleEnter(event,\"idno" . $ctr . "\");' /></td>"; echo "\n\t\t<td><input size='6' type='text' name='varqty[]' id='a" . $ctr . "' onkeypress='return handleEnter(event,\"varsublot" . $ctr . "\");' /></td>"; how about this code: <script type="text/javascript"> document.getElementById('c').onmousedown = function(){ subtract(document.getElementById('c'), document.getElementById('b'), document.getElementById('a'), document.getElementById('d')); } document.getElementById('b').onmousedown = function(){ subtract(document.getElementById('c'), document.getElementById('b'), document.getElementById('a'), document.getElementById('d')); } </script>
Jeremy | jfein.net
This should do it:
Code:<input type="text" id="c" value="0"/>-<input type="text" id="b" value="5"/>=<input disabled type="text" id="a" value="0" style="color:#000" /> <script type="text/javascript"> var c = document.getElementById('c'); var b = document.getElementById('b'); var a = document.getElementById('a'); //define c, b, a var performSubtract = function(e) { var key = e ? e.which : window.event.keyCode; //get the key, 13 = ENTER if(key == 13){ a.value = c.value - b.value; //subtract and set } }; c.onkeydown = b.onkeydown = performSubtract; </script>
Last edited by Nile; 12-10-2010 at 09:33 PM.
Jeremy | jfein.net
Bookmarks