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

I can't validate an array - help

I've pulled together an online form that creates a number of tables dependant on the results of a dropdown list, i.e. 2 from the list creates two input tables, 10 creates 10 tables etc.

The script for creating the tables is as follows;

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript"><!--
  2.     function fboxes(NumberOfBoxes){    
  3.     var i,boxes='';
  4.     for(i=0; i<NumberOfBoxes; i++){    
  5.     boxes += "<table width='400' border='0' cellspacing='0' cellpadding='0' align='left'><tr><td><strong>Location</strong></td><td><input type='textarea' name='locbox["+i+"]' id='locbox["+i+"]' size='30'></td></tr><tr><td colspan='2'><div align='center'><strong>Incident Details</strong></div></td></tr><tr><td colspan='2'><textarea name='textbox["+i+"]' id='textbox["+i+"]' cols='35' rows='8'></textarea></td></tr><tr><td colspan='2'><div align='center'><strong>Business Impact</strong></div></td></tr><tr><td colspan='2'><textarea name='bimpbox["+i+"]' id='bimpbox["+i+"]' cols='35' rows='8'></textarea></td></tr></table>";
  6.     }
  7.     document.getElementById('currentissues').innerHTML = boxes;
  8. }
  9.  
  10. --></script>
This is fine and the php page that is actioned upon validation can see the information from all the various tables.
What i need though is some validation for the boxes, namely, that if there is a table then the locbox[] field has to have text in it.

Each time I've tried to write the validation part for this section it says that "locbox" isn't defined, yest it is (as in the script above).

Any help at clearing this up and simplifying arrays would be greatly, muchly, enormously appreciated.
Aug 30 '07 #1
9 1625
r035198x
13,262 8TB
This would be JavaScript, wouldn't it? Ask in the JavaScript Forum! You know, Java isn't the same as JavaScript! ^^
Moved to Javascript forum
Aug 30 '07 #2
gits
5,390 Expert Mod 4TB
hi ...

how did you try to retrieve the textbox-values? to retrieve it the right way you should use for example:

Expand|Select|Wrap|Line Numbers
  1. var box_value = document.getElementById('locbox[1]').value;
  2.  
note: you cannot use locbox as an array or variable it is a simple string that is assigned to an elements id-attribute (respectivly its id-property too).

kind regards
Aug 30 '07 #3
I tried this for the validation;

Expand|Select|Wrap|Line Numbers
  1.    var total="";
  2.     for(var i=0; i < locbox; i++){
  3.     if(locbox[i].value =="") {
  4.     total +=document.locbox[i].value + "\n";
  5.     }
  6.     }
  7.     if(total=="") {
  8.     alert("fill something in");
  9.     return false;
  10.     }
(I've put the whole form here http://www.eds.shed.googlepages.com/morningstatus.html if you want to take a look and it includes the wrong validation)
Aug 30 '07 #4

note: you cannot use locbox as an array or variable it is a simple string that is assigned to an elements id-attribute (respectivly its id-property too).

kind regards
I don't understand why this is as the php file which runs after validation understands all of the locbox[] values as an array, why can't another script on the first page do this?
Aug 30 '07 #5
gits
5,390 Expert Mod 4TB
hmmm ... i'm confused now. where do you want to validate your values ... serverside or clientside?
Aug 30 '07 #6
hmmm ... i'm confused now. where do you want to validate your values ... serverside or clientside?
I'm validating the form clientside, hence the javascript, and using the php form to assemble the data and email it.
Aug 30 '07 #7
gits
5,390 Expert Mod 4TB
ok ... in that case you don't have defined a variable locbox for javascript since php writes the names/ids to the document and it is a simple textual attribute of the input-nodes ... you have to retrieve the values of your textboxes with dom-methods ... like i showed you ...

kind regards
Aug 30 '07 #8
ok ... in that case you don't have defined a variable locbox for javascript since php writes the names/ids to the document and it is a simple textual attribute of the input-nodes ... you have to retrieve the values of your textboxes with dom-methods ... like i showed you ...

kind regards
So would I have to write a var line for each of the possible box variables (possibly upto 10) like this:

Expand|Select|Wrap|Line Numbers
  1. var box_value0 = document.getElementById('locbox[0]').value;
  2. var box_value1 = document.getElementById('locbox[1]').value;
  3. etc
?
Aug 30 '07 #9
gits
5,390 Expert Mod 4TB
nope ... you may do something like the following:

Expand|Select|Wrap|Line Numbers
  1. var value_to_check;
  2. var boxes = document.getElementsByTagName('input');
  3.  
  4. for (var i = 0; i < boxes.length; i++) {
  5.     var box = boxes[i];
  6.  
  7.     if (/^locbox/.test(box.id)) {
  8.         value_to_check = box.value;
  9.         // check here the value_to_check ;) the way you want,
  10.         // or assign the values to an array or whatever
  11.     }
  12. }
  13.  
kind regards
Aug 30 '07 #10

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

Similar topics

0
by: tcarvin | last post by:
This is going to sound stupid, but I can't get the help to work in the Visual Studio .NET. I've tried using the help that comes with Studio and also from the MSDN. All I get is a generic...
1
by: Christina Feichter | last post by:
Hello All How can i start a help-file like help.chm? Thanks
1
by: ajliang | last post by:
How can I validate a proxy IP visit the web page? do you have any code example?
1
by: Simon Barnett | last post by:
Hi, RE: Converting pages including ASP pages for XHTML My question relates to ASP not ASP.NET - I can't find a newsgroup for ASP and hoped it was still relevant in ASP.NET - sorry if it's not....
2
by: arda | last post by:
how i can put 2d array to a pointer? In the below program i am giving a first value to output_bit and then start to a loop and putting the new values to an another array as called newdata. But as i...
7
by: recover | last post by:
class Obj { public: Obj(int a){} } class MyContainer { private: Obj m_obj;
3
by: =?Utf-8?B?UGxheWE=?= | last post by:
I am getting the following error when I try to write a value to my array. An unhandled exception of type 'System.NullReferenceException' occurred in EmpPrinting.exe Additional information:...
1
by: kiny3k | last post by:
hi, i have written this insert query for inserting data in database : "insert into leavemaster (leave_code,leave_desc,leave_type, leave_days, leave_valid_month, leave_amount, effective_date,...
1
by: comedydave | last post by:
Hi guys, I'm new to ASP and need some array help. I need to have a shopping cart. When you visit the site it creates a session and an array. When you click add to basket it adds the item ID to...
4
by: abhilash12 | last post by:
memory out of bound exception in javascript so pls tell me what is the reason
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.