473,835 Members | 1,778 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

I can't validate an array - help

12 New Member
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 1648
r035198x
13,262 MVP
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 Recognized Expert Moderator Expert
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
Dracenfels
12 New Member
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
Dracenfels
12 New Member

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 Recognized Expert Moderator Expert
hmmm ... i'm confused now. where do you want to validate your values ... serverside or clientside?
Aug 30 '07 #6
Dracenfels
12 New Member
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 Recognized Expert Moderator Expert
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
Dracenfels
12 New Member
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 Recognized Expert Moderator Expert
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
254
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 page-not- found kinda error. Any one else hit this? Tom
1
1672
by: Christina Feichter | last post by:
Hello All How can i start a help-file like help.chm? Thanks
1
2370
by: ajliang | last post by:
How can I validate a proxy IP visit the web page? do you have any code example?
1
2450
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. Problem: I am teaching myself about validating for XHTML and, upon testing a page I get errors for the use of the 'name' attribute in form fields. It seems that you have to replace the 'name' attribute for the 'id' attribute.
2
1912
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 understand from this loop the last value of the 2d array u is not put to newdata. Because of the first value of output_bit which is given in he beginning. In 1d array it is easy to solve this problem that you can put output_bit data in the for loop...
7
2092
by: recover | last post by:
class Obj { public: Obj(int a){} } class MyContainer { private: Obj m_obj;
3
1107
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: Object reference not set to an instance of an object. This error only occurs when I don't include an initial size in my declareation (ex. DIM strArray( ) as String). If I declare an array with an initial size (ex. DIM strArray(11) as String) then it...
1
1229
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, max_limit, leave_num, maintain_bal, leave_encash, leave_fq, encash_limit, encash_fq, carry_frwd, negative_bal, max_encash_bal, leave_limit, holiday_lv, weekoff_lv, del_flag" & _ "values (@leave_code, @leave_desc, @leave_type, @leave_days,...
1
1524
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 the array. I can't get my head around how i allocate it an array slot and then empty out the array in the checkout. I presume i'd need a loop or something to go through each array item and print it out. Thanks in advance,
4
2405
by: abhilash12 | last post by:
memory out of bound exception in javascript so pls tell me what is the reason
0
9652
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10808
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10560
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10233
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9344
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7766
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6963
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5636
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
3088
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.