473,396 Members | 1,734 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.

Dynamic input form...

Hi,

This is not just a simple input form made with javascript. This is the code:

Expand|Select|Wrap|Line Numbers
  1. <html><head>
  2. <script language="JavaScript">
  3. var i=0;
  4. function add(inputEvent, inputDur, inputCode, placeEvent, placeDur, placeCode, placeDel, elmnt, inputButton) {
  5.  
  6.  
  7.     var event = document.getElementById(inputEvent);
  8.     var val = document.getElementById(inputDur);
  9.     var code = document.getElementById(inputCode);
  10.  
  11.     if (event.value == null || val.value == null || event.value == "" || val.value == "")
  12.     {
  13.         alert("Please set Event and Duration before clicking Add !");
  14.         return;
  15.     }
  16.     if (document.getElementById(inputCode))
  17.     {
  18.         if (code.value == null || code.value == "")
  19.         {
  20.             alert("Please set Event,Duration and Code before clicking Add !");
  21.             return;
  22.         }
  23.     }
  24.  
  25.     /* Define ID of input */
  26.     i++
  27.  
  28.     var elem = document.createElement("input");
  29.     elem.setAttribute("type", "text");
  30.     elem.setAttribute("class", "box");
  31.     elem.setAttribute("value", event.value);
  32.     elem.setAttribute("id", i);
  33.     elem.setAttribute("disabled", "");
  34.     elem.setAttribute("style", "width: 100px ! important;padding: 3px 5px;")
  35.     var elemh = document.createElement("input");
  36.     elemh.setAttribute("type", "hidden");
  37.     elemh.setAttribute("value", event.value);
  38.     elemh.setAttribute("name", "code");
  39.     elemh.setAttribute("id", i);
  40.     var elem2 = document.createElement("input");
  41.     elem2.setAttribute("type", "text");
  42.     elem2.setAttribute("class", "box");
  43.     elem2.setAttribute("value", val.value);
  44.     elem2.setAttribute("id", i);
  45.     elem2.setAttribute("disabled", "");
  46.     elem2.setAttribute("style", "width: 100px ! important; padding:3px 5px;")
  47.     var elemh2 = document.createElement("input");
  48.     elemh2.setAttribute("type", "hidden");
  49.     elemh2.setAttribute("value", val.value);
  50.     elemh2.setAttribute("name", "value");
  51.     elemh2.setAttribute("id", i);
  52.     var elem3 = document.createElement("input");
  53.     elem3.setAttribute("type", "button");
  54.     elem3.setAttribute("value", "Delete");
  55.     elem3.setAttribute("id", i);
  56.     elem3.setAttribute('onclick', 'del("' + i + '","' + elmnt + '","' + inputButton + '")');
  57.     elem3.setAttribute("style", "width: 60px ! important;")
  58.  
  59.     if (inputCode != 'false')
  60.     {
  61.         var elem4 = document.createElement("input");
  62.         elem4.setAttribute("type", "text");
  63.         elem4.setAttribute("class", "box");
  64.         elem4.setAttribute("value", code.value);
  65.         elem4.setAttribute("name", "value");
  66.         elem4.setAttribute("id", i);
  67.         elem4.setAttribute("disabled", "");
  68.         elem4.setAttribute("style", "width: 100px ! important;")
  69.         var elemh4 = document.createElement("input");
  70.         elemh4.setAttribute("type", "hidden");
  71.         elemh4.setAttribute("value", code.value);
  72.         elemh4.setAttribute("name", "value");
  73.         elemh4.setAttribute("id", i);
  74.     }
  75.  
  76.     document.getElementById(placeEvent).appendChild(elem);
  77.     document.getElementById(placeEvent).appendChild(elemh);
  78.     document.getElementById(placeDur).appendChild(elem2);
  79.     document.getElementById(placeDur).appendChild(elemh2);
  80.     if (inputCode != 'false')
  81.     {
  82.         document.getElementById(placeCode).appendChild(elem4);
  83.         document.getElementById(placeCode).appendChild(elemh4);
  84.     }
  85.     document.getElementById(placeDel).appendChild(elem3);
  86.  
  87.     child1 = elem;
  88.     childh1 = elemh;
  89.     child2 = elem2;
  90.     childh2 = elemh2;
  91.     child3 = elem3;
  92.  
  93.  
  94.     document.getElementById(inputEvent).value = "";
  95.     document.getElementById(inputDur).value = "";
  96.     if (document.getElementById(inputCode))
  97.         document.getElementById(inputCode).value = "";
  98.  
  99. }
  100.  
  101. function del(id, elmnt, inputButton)
  102. {
  103.     while (document.getElementById(id) != null)
  104.     {
  105.         parentObject = document.getElementById(id).parentNode;
  106.         childObject = document.getElementById(id);
  107.         parentObject.removeChild(childObject);
  108.     }
  109.     if(navigator.navigator.userAgent.match(/MSIE/gi))
  110.     {
  111.         parentObject = document.getElementById(id).parentNode;
  112.         childObject = document.getElementById(id);
  113.         parentObject.removeChild(childObject);
  114.  
  115.     }
  116. }
  117.  
  118. </script>
  119. </head>
  120. <body>
  121. <table cellspacing="0" width="260px">
  122.     <tr>
  123.         <td>Event</td>
  124.         <td>Duration</td>
  125.         <td>&nbsp;</td>
  126.     </tr>
  127.     <tr>
  128.         <td style="width: 100px !important;">
  129.             <input id="event_input" value="" name="event_play" type="text" style="width: 100px !important;">
  130.         </td>
  131.         <td style="width: 100px !important;">
  132.             <input id="duration_input" value="" name="duration_play" type="text" style="width: 100px !important;">
  133.         </td>
  134.         <td style="width: 60px !important;">
  135.             <input value="Add" onclick="add('event_input','duration_input','false','event','duration','false','del','playGame','playGameButton')" type="button"  style="width: 60px !important;">
  136.         </td>
  137.     </tr>
  138.     <tr>
  139.         <div style="overflow-y: scroll;">
  140.             <td id="event">
  141.  
  142.             </td>
  143.             <td id="duration">
  144.  
  145.             </td>
  146.             <td id="del">
  147.  
  148.             </td>
  149.         </div>
  150.     </tr>
  151. </table>
  152. </body>
  153. </html>
  154.  
In this code, some of the elements in the function (del(elmnt, InputButton) and etc...) are not used, but they are used in the actual code for different purpose.

The problem is that I need not only 1 input to be inserted, but 2 or 3 inputs with same ID. This code actually works fine in FF, but it the part with the deleting of the inputs doesn't work in IE.
Could somebody give me a hand with this one ? I'll appreciate it very much!


Thanks in advance,
The Devil
Jan 1 '08 #1
5 2281
Couldn't someone help me ?
Jan 2 '08 #2
gits
5,390 Expert Mod 4TB
you cannot have the same id in one page ... id has to be unique ... like the name id says:) ... you can have elements with the same names. having the same id for multiple elements then document.getElementById() will fail ...

kind regards
Jan 2 '08 #3
acoder
16,027 Expert Mod 8TB
IE doesn't like setting event handlers with setAttribute, so you'll have to replace it with the good old elem.onclick = ..., etc.
Jan 2 '08 #4
Thanks !
That gave me an idea how to fix the problem ! Thanks a lot !

Best wishes !
Jan 2 '08 #5
acoder
16,027 Expert Mod 8TB
No problem, glad it helped.
Jan 3 '08 #6

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

Similar topics

11
by: propizzy | last post by:
Appreciate any help!!! PROBLEM: I have this form that allows the user to dynamically create additional fields (see javascript code bellow). I am trying to retrieve the values entered into these...
2
by: Nick | last post by:
Loop to create an array from a dynamic form. I'm having trouble with an application, and I'll try to explain it as clearly as possible: 1. I have a form with two fields, say Apples and...
1
by: SAN CAZIANO | last post by:
I have create a dynamic html table by adding some rows where I have to put some value in an input field and now how can I get all value of all row ??? I try this but it doesn' work button...
4
by: pizzy | last post by:
INTRO: I tried to clean it up for easy reading. I hope I didn't make any mistakes. PROBLEM: WOW, this is some crazy sh!t. I can't get my checkbox (see "TAGSELECTED") to print my textboxes (see...
0
by: Pat Patterson | last post by:
I'm having serious issues with a page I'm developing. I just need some simple help, and was hoping someone might be able to help me out in here. I have a form, that consists of 3 pages of...
3
by: Leo J. Hart IV | last post by:
OK, here's another question for the experts: I am building a multi-step (3 steps actually) form using a panel for each step and hiding/displaying the appropriate panel/panels depending on which...
2
by: assgar | last post by:
Hi Developemnt on win2003 server. Final server will be linux Apache,Mysql and PHP is being used. I use 2 scripts(form and process). The form displays multiple dynamic rows with chechboxs,...
0
bmallett
by: bmallett | last post by:
First off, i would like to thank everyone for any and all help with this. That being said, I am having a problem retrieving/posting my dynamic form data. I have a form that has multiple options...
2
by: yomadhu | last post by:
I created a dynamic form in javascript. Am unable to get those values in to php to display. I need all details. If i add 10 rows the i need to display those all values. Can any one help me for that...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.