473,385 Members | 1,387 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,385 software developers and data experts.

What am I missing?

So, I've got this dynamic form element thing goiing on, but I'm getting the output undefined. I know it's goiing to be something simple I'm missing, but I'm just not figuring it out.

FUNCTION

function grplist() {
var num=document.form1.rms.value
for (var n=0;n<num;n++) {
document.write("<input name='guest"+n+"' type='text' id='guest"+n+"' size='20' />");
}
}

The call to the function happens on page load, and after an onChange="history.go(0)". Prints the form elements just fine, but there is always the undefined after the last box. Please help make it go away. :)
Feb 28 '07 #1
22 1489
iam_clint
1,208 Expert 1GB
show us the form

also add ; after var num=document.form1.rms.value

Expand|Select|Wrap|Line Numbers
  1. <script>
  2. function grplist() {
  3. var num=document.form1.rms.value
  4. for (var n=0;n<num;n++) {
  5. document.write("<input name='guest"+n+"' type='text' id='guest"+n+"' size='20' />");
  6. }
  7. }
  8. </script>
  9. <form name="form1">
  10. <input type="text" name="rms" id="rms">
  11. <input type="button" onclick="grplist();" value="click me">
  12. </form>
  13.  
this worked fine for me..
Feb 28 '07 #2
Wow, thanks for the fast reply.
Well, it's a decent length form, so here's the parts that matter;

<input name="rms" type="text" id="rms" size="3" class="bold" onchange="history.go(0);" />

<td><script type="text/javascript">
{
document.write(grplist())
}
</script></td>
</tr>
All in form form1.
So, when the user tabs out of "rms", the page refreshes and the grplist() is written again. The ; doesn't seem to make a difference btw. When I tried on a fresh page with your code, it plugged in the undefined too.
Feb 28 '07 #3
iam_clint
1,208 Expert 1GB
why are you trying to write document.write(grplist()) to the screen
of course this is going to return undefined
Feb 28 '07 #4
why are you trying to write document.write(grplist()) to the screen
of course this is going to return undefined
I'm trying to display the correct number of text boxes according to the "rms" value. What's the better option? I've been hammering away at this for a bit.
Feb 28 '07 #5
iam_clint
1,208 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. <script>
  2. function grplist() {
  3. var num=document.form1.rms.value
  4. var tmp = ""
  5. for (var n=0;n<num;n++) {
  6. tmp += "<input name='guest"+n+"' type='text' id='guest"+n+"' size='20' />";
  7. }
  8. document.getElementById("formstuff").innerHTML = tmp;
  9. }
  10. </script>
  11. <form name="form1">
  12. <input name="rms" type="text" id="rms" size="3" class="bold" onchange="grplist();" />
  13. </form>
  14. <div id="formstuff"></div>
  15.  
try this out for size

of course put the div where u want it to be written and change the rms onchange to how i have it.
Feb 28 '07 #6
Expand|Select|Wrap|Line Numbers
  1. <script>
  2. function grplist() {
  3. var num=document.form1.rms.value
  4. var tmp = ""
  5. for (var n=0;n<num;n++) {
  6. tmp += "<input name='guest"+n+"' type='text' id='guest"+n+"' size='20' />";
  7. }
  8. document.getElementById("formstuff").innerHTML = tmp;
  9. }
  10. </script>
  11. <form name="form1">
  12. <input name="rms" type="text" id="rms" size="3" class="bold" onchange="grplist();" />
  13. </form>
  14. <div id="formstuff"></div>
  15.  
try this out for size

of course put the div where u want it to be written and change the rms onchange to how i have it.
For-the-luv-of-God! I was tryiing to figure that out yesterday!! lol The broken way just worked first. I was tryiing to manipulate the input tag though, not a div. So close, yet so clueless. :) Thank you very much.
Feb 28 '07 #7
iam_clint
1,208 Expert 1GB
np if you need more help just come back and post.

welcome to the scripts

New posts come into my email thats why it was a quick response cause i was just sitting here doing nothing :P
Feb 28 '07 #8
So ... about that Internet Explorer.

I went one step further, 'cause i can't help myself, and worked the code for a table row instead of a div tag. Works great in FF, error code 0 as soon as it tries to output the <td> cell HTML in IE. Any thoughts? It's quite slick in FF. Otherwise I have to work out some convoluted row/div fix. Or scrap the table theory all together.
Expand|Select|Wrap|Line Numbers
  1. function types(tip){
  2.     var num=document.form1.rms.value
  3.     var tmp = "<strong>Please enter all expected guests names:</strong><br />"
  4.     for (var n=0;n<num;n++) {
  5.     tmp += "Guest name: <input name='guest"+n+"' type='text' id='guest"+n+"' size='15' /> Service Num: <input name='guestnum"+n+"' type='text' id='guestnum"+n+"' size='15' /><br />";
  6.     }
  7.     if (tip=="ind"){
  8.     document.getElementById("grpbook").style.visibility="hidden"
  9.     document.form1.unit.style.visibility="hidden";
  10.     document.getElementById("glist").innerHTML="";
  11.     }
  12.     else{
  13.     document.getElementById("grpbook").style.visibility="visible";
  14.     document.form1.unit.style.visibility="visible";
  15.     document.getElementById("glist").innerHTML="<td valign='top' class='lft'><strong>Guest List:</strong></td><td colspan='3' class='l'>"+tmp+"</td>";
  16.     }
  17. }
Where id="glist" is the table row id. Am I outta whack again in my thought process?
Feb 28 '07 #9
iam_clint
1,208 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. <script>
  2. function types(tip){
  3.         var num=document.form1.rms.value
  4.  var tmp = "<strong>Please enter all expected guests names:</strong><br />"
  5.  for (var n=0;n<num;n++) {
  6.  tmp += "Guest name: <input name='guest"+n+"' type='text' id='guest"+n+"' size='15' /> Service Num: <input name='guestnum"+n+"' type='text' id='guestnum"+n+"' size='15' /><br />";
  7.  }
  8.  if (tip=="ind"){
  9.  document.getElementById("grpbook").style.visibility="hidden"
  10.  document.form1.unit.style.visibility="hidden";
  11.  document.getElementById("glist").innerHTML="";
  12.  }
  13.  else{
  14.  document.getElementById("grpbook").style.visibility="visible";
  15.  document.form1.unit.style.visibility="visible";
  16.         addcolumn('glist', '<strong>Guest List:</strong>', 'lft', 'top', 'center');
  17.         addcolumn('glist', tmp, 'lft', 'top', 'center');
  18.  }
  19. }
  20. function addcolumn(rowid, ctext, tclass, tvalign, talign) {
  21.  var trow = document.getElementById(rowid);
  22.  var tcolumn = document.createElement("td");
  23.  tcolumn.setAttribute("class", tclass);
  24.  tcolumn.setAttribute("valign", tvalign);
  25.  tcolumn.setAttribute("align", talign);
  26.  tcolumn.innerHTML = ctext;
  27.  trow.appendChild(tcolumn);
  28. }
  29. </script>
  30.  

I wrote the function addcolumn hope it works for you good luck post if you need help
Feb 28 '07 #10
So, I won't pretend to entirely follow the new theory, but i get the gist. What I don't get is why the innerHTML for the <td> will work in FF but not IE.

Oh, and I can pick apart the extra columns you aded. Or not. Guess we'll see. ;)
Feb 28 '07 #11
iam_clint
1,208 Expert 1GB
because they are different enough said :P you will fight between the 2 like cats tails tied togethor and thrown over a clothes line (no i haven't done this) (recently)
Feb 28 '07 #12
because they are different enough said :P you will fight between the 2 like cats tails tied togethor and thrown over a clothes line (no i haven't done this) (recently)
Well, I can appreciate the witty stab, but WHY are they different? Oh, and we have a problem :) Well, I do.
Every time the types function is called another column is added TO, but does not replace the first ones. Oh, and IE still doesn't look right. It is creating a 4 columns rather than 2. I fixed it in FF by adding a colspan variable to the addcolumn function, but it didn't have any effect in IE. :(
Feb 28 '07 #13
iam_clint
1,208 Expert 1GB
they are different due to the way they interpret the w3c standards


Ie was out before the standards were even in place (I think) but in any case its the way they handle the code.

post a link to the page you are working on.
Feb 28 '07 #14
iam_clint
1,208 Expert 1GB
to get rid of the columns you need to give each new column a name and loop through them and removeChild instead of appendChild
Feb 28 '07 #15
they are different due to the way they interpret the w3c standards


Ie was out before the standards were even in place (I think) but in any case its the way they handle the code.

post a link to the page you are working on.
http://book.cfbtrenton.com/filloutn.php
Change the number of guests first and all looks perfect in FF, but not IE. Click Group Booking radio button, or change the number again, and another column is added. Just want it to look like when it first runs on FF, and then replace itself if it gets called again.
Feb 28 '07 #16
iam_clint
1,208 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. function types(tip){
  2.  var num=document.form1.rms.value
  3.  var tmp = "<strong>Please enter all expected guests names:</strong><br />"
  4.  for (var n=0;n<num;n++) {
  5.  tmp += "Guest name: <input name='guest"+n+"' type='text' id='guest"+n+"' size='15' /> Service Num: <input name='guestnum"+n+"' type='text' id='guestnum"+n+"' size='15' /><br />";
  6.  }
  7.  if (tip=="ind"){
  8.  document.getElementById("grpbook").style.visibility="hidden"
  9.  document.form1.unit.style.visibility="hidden";
  10.  document.getElementById("glist").innerHTML="";
  11.  }
  12.  else{
  13.  document.getElementById("grpbook").style.visibility="visible";
  14.  document.form1.unit.style.visibility="visible";
  15.  var trow = document.getElementById('glist');
  16.  removeChildren(trow);
  17.  addcolumn('glist', '<strong>Guest List:</strong>', 'lft', 'top', 'center', '1');
  18.  addcolumn('glist', tmp, 'lft', 'top', 'center', '3');
  19.  }
  20. }
  21. function addcolumn(rowid, ctext, tclass, tvalign, talign, span) {
  22.  var trow = document.getElementById(rowid);
  23.  var tcolumn = document.createElement("td");
  24.  tcolumn.setAttribute("class", tclass);
  25.  tcolumn.setAttribute("valign", tvalign);
  26.  tcolumn.setAttribute("align", talign);
  27.  tcolumn.setAttribute("colspan", span);
  28.  tcolumn.innerHTML = ctext;
  29.  trow.appendChild(tcolumn);
  30. }
  31. function removeChildren(obj) {
  32.  while (obj.hasChildNodes()) obj.removeChild(obj.firstChild);
  33. }
  34.  
  35.  
give this a whirl
Feb 28 '07 #17
F MS. WTH won't rowspan work in IE? lol
Feb 28 '07 #18
iam_clint
1,208 Expert 1GB
but did this fix your problem? make your table bigger or width 100% the td with set attribute.



and for a number being passed through it doesn't need to be '3' but 3

and do it this way..
tcolumn.colSpan = span;
Feb 28 '07 #19
The column gets replaced when the function is called, but IE is still messed up. rowspan seems to not work. Actually, none of the attributes are working in IE. It's ignoring the class assignment alltogether. Plus the valign, well, everything. Stupid MS.
Feb 28 '07 #20
The column gets replaced when the function is called, but IE is still messed up. rowspan seems to not work. Actually, none of the attributes are working in IE. It's ignoring the class assignment alltogether. Plus the valign, well, everything. Stupid MS.
Ah hah!!!
Expand|Select|Wrap|Line Numbers
  1. tcolumn.className = tclass;
instead of
Expand|Select|Wrap|Line Numbers
  1.  tcolumn.setAttribute("class", tclass);
worked!!
Feb 28 '07 #21
iam_clint
1,208 Expert 1GB
good good, your the first person i had to go to 3 pages of posting with :P

by the way you have an error on line 270
Calendar is undefined
Feb 28 '07 #22
good good, your the first person i had to go to 3 pages of posting with :P

by the way you have an error on line 270
Calendar is undefined
Well, thank you very much for the help. And, I know. It's a copy of the working page and I was too lazy to add my includes. :)
Feb 28 '07 #23

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

Similar topics

28
by: David MacQuigg | last post by:
I'm concerned that with all the focus on obj$func binding, &closures, and other not-so-pretty details of Prothon, that we are missing what is really good - the simplification of classes. There are...
5
by: SimpSity | last post by:
I am a complete noob, what book would be the best for complete begginers, u know the ones that could teach a a retarted neborn monkey to program C++ thats the kind of thing im looking for alotr of...
112
by: Andy | last post by:
Hi All! We are doing new development for SQL Server 2000 and also moving from SQL 7.0 to SQL Server 2000. What are cons and pros for using IDENTITY property as PK in SQL SERVER 2000? Please,...
1
by: Sarah | last post by:
Hello. I am using Microsoft.Office.Interop.Excel in a C# .NET project. I want to open an Excel application with a specific file name. I am currently opening it with this code: ...
1
by: bradleyc | last post by:
Definately need my eyes checked... Error:asstester.cpp(300,1):Declaration missing ; Error:asstester.cpp(300,1):Compound statement missing } void doModify() { clrscr(); char inputv,...
0
by: kris | last post by:
hi can any one help me out, i have written a code for Word Indexing using Dll's i think this is an incomplete code for WORD INDEX. I had encountered this error "Error! No index entries found"...
17
by: Justin Emlay | last post by:
I'm hopping someone can help me out on a payroll project I need to implement. To start we are dealing with payroll periods. So we are dealing with an exact 10 days (Monday - Friday, 2 weeks). ...
10
by: Protoman | last post by:
Could you tell me what's wrong with this program, it doesn't compile: #include <iostream> #include <cstdlib> using namespace std; class Everything { public: static Everything* Instance()
5
by: le0 | last post by:
Hello guys, Im really having a hard time doing this, I have a record set with the ItemNo field with the data type as Text. In the record that I have, I want to find the missing number in the...
20
by: mc | last post by:
I may be opening a can of worms and don't want to start a religious war, but... What features of Java do Java programmers miss when working in C#? Other than, of course, great portability. C#...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...

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.