473,473 Members | 2,166 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Multiple data sets in a form

11 New Member
For certain reason, I need to check the validity of a form when submit with many data with shared name. The form looks like this:

[HTML]<form id="upload_form" name="upload_form" onsubmit="return uploadCheckValid2()">
<table>
<tr>
<td>xxx</td>
</tr>
<tr>
<td>
<input type="text" name="title[]" value="10" />
</label></td>
....
....
</form>[/HTML]

For the js:
Expand|Select|Wrap|Line Numbers
  1. function uploadCheckValid2()
  2. {
  3.     var titles = document.forms[0].elements['title'][0].value;
  4.     alert(titles);
  5.         if(xxx != xxx)
  6.     return false;
  7. }
I don't even able to alert the nodeName or value. Could anyone help??
Mar 17 '08 #1
11 1534
gits
5,390 Recognized Expert Moderator Expert
give your input-nodes an id and refer with:

Expand|Select|Wrap|Line Numbers
  1. var node = document.getElementById('the_id');
kind regards
Mar 17 '08 #2
hkma08
11 New Member
i have 10 inputs per table, and will have 5 tables in max. So your way works but will be very long in code. Any other ways?
Mar 17 '08 #3
gits
5,390 Recognized Expert Moderator Expert
do you mean you want to check all input nodes for the same thing? then just use:

Expand|Select|Wrap|Line Numbers
  1. document.getElementsByTagName('input');
and check for the type == text and its values ...

kind regards
Mar 17 '08 #4
hkma08
11 New Member
Although the name attached to me is newbie, i don't think this is that easy to solve, and probably this is advance stuff.

May be i should explain more further on what i want to do. Did you notice that the name i gave to the input has braces? such as name="title[]". I have a table with following inputs:

title, author, isbn, post date etc...

when i hit an 'add' button, the table is duplicated with same structure, including names and ids. And in order to save to database by php, i have to use name="title[ ]" instead of just name="title" (w/o braces), since there is multiple record sets. When i was doing w/o multiple data sets, i used:

document.forms[' myform '][' title ']
or other ways such as the way you mentioned.

I tried and stuck on that the following ways do not work at all:
document.forms[' myform '][' title[ ] ']
or for (i=0;i<5;i++) { document.forms[' myform '][' title '][ i ] .......... }

simple example is that i have several isbn, all used share name, isbn[], the data pass to php is array of data, i am able to extract it to php, but not able to check every isbn is 10 or 13 digits (according to international book numbering) by javascript.

Get it? Excuse me for this complicated problem. But I am getting crazy on this ........ Please help if possible.
Mar 18 '08 #5
acoder
16,027 Recognized Expert Moderator MVP
How about document.getElementsByName("title[]") ?
Mar 19 '08 #6
hkma08
11 New Member
i tried this, doesn't work either...

var form = document.getElementById(formid);
var titles = form.getElementsByName('title[]');
alert(titles[0].value);
Mar 23 '08 #7
acoder
16,027 Recognized Expert Moderator MVP
getElementsByName is a method of the Document object. Try:
Expand|Select|Wrap|Line Numbers
  1. var titles = form.elements['title[]'];
instead.
Mar 24 '08 #8
hkma08
11 New Member
oh, i finally got it in some way.

Expand|Select|Wrap|Line Numbers
  1. function checkBookUploadValid(theForm)
  2. {
  3.     var inputs = theForm.getElementsByTagName('input');
  4.     for (var i=0; i<inputs.length; i++)
  5.     {
  6.         if (inputs[i].name == 'title[]')
  7.         {
  8.             if(inputs[i].value == '') {inputs[i].style.background = error_color; return false;}
  9.             else {inputs[i].style.background = 'white';}
  10.         }
  11. .....
  12. .....
  13. .....
  14. }
  15.  
This way works good. But still thanks to you guys trying to answer me..
Mar 26 '08 #9
acoder
16,027 Recognized Expert Moderator MVP
That's similar to what gits suggested, but anyway I'm glad you've managed to solve it.
Mar 27 '08 #10
hkma08
11 New Member
oh it is!
probably i was so stuck on something and misunderstand what he said.
my bad.
Mar 28 '08 #11
acoder
16,027 Recognized Expert Moderator MVP
Hey, no problem. At least it's working and that's what we're here for.
Mar 31 '08 #12

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

Similar topics

2
by: scott | last post by:
Hi, I'm having some trouble with something that should be relatively easy. I want to update multiple rows in one of my database tables simultaneously. In my table I have these values: ...
3
by: wxbuff | last post by:
I have a report based on our product names that consists of two parts. Both insert data into a temporary table. 1. A single grouped set of results based on all products 2. Multiple tables based...
5
by: Stanley Sinclair | last post by:
I have a need to return multiple result sets from a stored procedure. Want that SP to call others to get the data. Win2003, db2 8.1.5. Can't figure out how to handle open cursors, and return...
4
by: William Wisnieski | last post by:
Hello Everyone, Access 2000 I have a form with multiple pages on it. There is one text field on the third page of the form that I need the user to complete before leaving the form or moving...
6
by: mark | last post by:
I have an asp.net ecommerce web application on a remote web server. I'm using an Access database on the back end. I've notice a few strange things. When I mimic an multiple user environment by...
2
by: Leventcos21 | last post by:
Hi all, I have been stuck on this issue for weeks now and can not find a solution, so I hoping that someone can help me out. I am setting up a training database. I have setup the structure and...
14
by: =?Utf-8?B?UHVjY2E=?= | last post by:
Hi, I'm using VS2005 and .net 2.0. I'm creating an application that has 3 forms. I want allow users to move forward and backward with the forms and retain the data users have entered. I thought...
2
by: =?Utf-8?B?VGVycnk=?= | last post by:
I have coded multiple select statements in a single stored procedure, and when I execute this procedure on SQL Server Management Express, I correctly get multiple result sets. But, if I try to add...
0
by: TechnoAtif | last post by:
<?php include "dbconnect.php"; include "commonFunc.php"; ?> <!----------------------------------> <table width="80%" border="1" cellpadding="2" cellspacing="0"> <tr > <td...
4
by: phill86 | last post by:
Hi, i have a form that runs a query in a recordset on the after update method if i copy and paste one record at a time the query picks up the records in the underlying table but if i paste...
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,...
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...
1
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.