473,396 Members | 1,998 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Javascript combined with php. (works in explorer but not in firefox) getElementById

3
Dear community,


I created a small form witch is supposed to automatically calculate the price via onKeyUp=()

and in explorer all is working fine but in explorer the script goes exactly untill the following line.
document.getElementById(naam+"txt").value='';
after that the script quits no error it just stops.

I'll try to make the code as short as possible
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>Index pagina</title>
  4. <script type="text/javascript">
  5. //small script to see if it is a number or not
  6. function is_int(value){
  7.   if((parseFloat(value) == parseInt(value)) && !isNaN(value)){
  8.       return true;
  9.   } else {
  10.       return false;
  11.   }
  12. }
  13. //calculate the total price
  14. function totaal()
  15.   var prijs= 0;
  16.   <?php 
  17.  $X= array("spagGR","* Spaghetti","-groot:",7.5);
  18.   ?>
  19.       prijs = prijs+(<?php echo $X[3];?>* document.getElementById("<?php echo $X[0]; ?>txt").value);
  20.  
  21.  
  22.   document.getElementById("totaal").innerHTML=prijs;
  23.   return;
  24. }
  25. function berekenen(str, prijs, naam)
  26. {
  27.   //alert(str+prijs+naam);
  28.   //check if it is filled in
  29.   if (str.length==0)
  30.     { 
  31.     document.getElementById(naam).innerHTML="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
  32.     totaal()
  33.     return;
  34.     }
  35.   //check if it is a number
  36.   if (is_int(str)==false)
  37.     {
  38.     alert("Gelieve een cijfer in te vullen.");
  39.     document.getElementById(naam).innerHTML="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
  40.     document.getElementById(naam+"txt").value='';
  41.     totaal()
  42.     return;
  43.     }
  44.     //calculate the price
  45.     document.getElementById(naam).innerHTML=str*prijs;
  46.     totaal()
  47.     return;
  48. }
  49. </script>
  50. </head>
  51. <body>
  52. <FORM METHOD="post" TARGET="_self" ACTION="pastabasta.php?p=3">
  53.   <table border=0 cellpadding=0 cellspacing=0>
  54.     <?php
  55.       $X= array("spagGR","* Spaghetti","-groot:",7.5);
  56.     ?>
  57.     <tr>
  58.       <td><?php echo $X[1];?></td>
  59.       <td><?php echo $X[2];?></td>
  60.       <td><?php echo "&euro; ".$X[3]; ?></td>
  61.       <td class="puntjesTD">-><INPUT class="puntjes" maxlength="2" NAME="<?php echo $X[0];?>txt" SIZE="1" onKeyUp="berekenen(this.value,<?php echo $X[3]; ?>,'<?php echo $X[0];?>')" ></td>
  62.       <td>X<?php echo $X[3]."=";?></td><td><em id="<?php echo $X[0];?>" name="<?php echo $X[0];?>" class="puntjes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</em></td></tr><tr>
  63.       <td colspan="5" align="right">Totaal bedrag: </td><td><em id="totaal" name="totaal" class="puntjes" >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</em></td>
  64.     </tr> 
  65.   </table>
  66. </FORM>
  67. </body>
  68. </html>

I have also tried replacing getElementById with document.forms['name_of_form'].name_of_input.value

but I still get the same issue...

any idea is welcome!

normally you can check the result on http://joop.vazant.be/www/chiro/pastabasta.php
and the send option isn't written yet so feel free to test what you like :)

the best place to change something for testing is right after the second alert.
Expand|Select|Wrap|Line Numbers
  1. if (is_int(str)==false)
  2.     {
  3.     alert("Gelieve een cijfer in te vullen.");
  4.     document.getElementById(naam).innerHTML="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
  5.     document.getElementById(naam+"txt").value='';
  6.  
(the innerhtml still gets executed and the elementbyid stops the script)
Nov 17 '11 #1

✓ answered by acoder

It would go around the value from the text box.

Looking at your code again, I notice that you've only set a name to the input box and no ID whereas you attempted to get the element by its id.

4 1681
acoder
16,027 Expert Mod 8TB
Don't forget to put parse the value using parseInt/Float, e.g. on line 20.
Nov 17 '11 #2
4aces
3
what should I parseInt/Float afterwards?
srr I got the function for checking if it is an integer from a differend site I'm still very new at this :)

I have been trying a differend approach via the
Expand|Select|Wrap|Line Numbers
  1. eval("document.forms['formulier']."+naam+"txt.value")="";
but this seems to be giving even more issues :)
(solved that issue via:
Expand|Select|Wrap|Line Numbers
  1. var formObj = eval("document.formulier."+naam+"txt");
  2. formObj.value = tes;

switching to
Expand|Select|Wrap|Line Numbers
  1. document.formulier.elements[naam+"txt"].value = "";
works again in explorer but not in firefox :s


but well can you please give an extra note on the parseInt/Float as I'm affraid I dont understand what you mean.
Nov 17 '11 #3
acoder
16,027 Expert Mod 8TB
It would go around the value from the text box.

Looking at your code again, I notice that you've only set a name to the input box and no ID whereas you attempted to get the element by its id.
Nov 18 '11 #4
4aces
3
omg
I have rewritten that part like 10 times and thats the problem. I forgot the ID tag in the inputfield :s

thanks acoder
for the value from the textbox it gets tested
if (is_int(str)==false) the is_int checks if it is a number or not


1000* thnx acoder
I have been looking at that code for houres and houres :)
Nov 18 '11 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Tom Petersen | last post by:
I must have the format of the below line wrong for IE: click <a href="cal.asp?sdate=<% =strDate1 %>&location=<% =strLocation %>&eTime=<% =strDate2 %>">here</a> to add this information to your...
7
by: CFonville | last post by:
I have a script that is working fine in the latest version of Firefox with no errors or warnings, but does not work in IE. I have several select boxes that, when changed, update some text (a...
3
by: patrickkellogg | last post by:
I have this code when you click the buttom is suppose to add a job history. it works with firefox, opera, but not ie. (please note - new entries don't have all the elements in them yet, but...
2
alexphd
by: alexphd | last post by:
This code works in firefox perfectly, but in Internet Explorer it does not calculate the total correctly. Anybody know why? <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"...
3
by: jnhemley | last post by:
I have a script that works in Firefox but not IE6- <script language="JavaScript" type="text/javascript"> document.Params.ThisPageURL.value=document.URL; var x = new Date ();...
3
by: safiratec | last post by:
Hi, I want to show a div depending of the value of a <select> option, using 2 functions hidediv() and showdiv() - it is working fine in firefox, but not in IE (tested with IE 6 and 7). <body...
8
by: SJ Carter | last post by:
Hello guys, I have the following piece of code: function validate() { var f = document.form1; if (f.name.value == "" || f.name.value == '' || f.name.value.length == 0) { alert('Please enter...
3
by: RamNivas | last post by:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1- transitional.dtd"> <html> <head> <title>Login</title> <style type="text/css"> h1 {...
4
by: lisa007 | last post by:
this link works on firefox but not on explorer help please cant seem to see whats wrong with it <li> <a href="resume.html"> <button class="rounded"> <span>Contact</span> </button>...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.