www.webdeveloper.com
Results 1 to 4 of 4

Thread: need help collecting data

  1. #1
    Join Date
    Mar 2012
    Posts
    41

    need help collecting data

    this is part of the code
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html>
    <head>
    <script>
    function AddInput(k) {
    			
    			var newSerial = document.createElement('input');
    			var newComment = document.createElement('input');
    			var newBreak = document.createElement('br')
    			
    			newSerial.type = "text";
    			newComment.type = "text";
    			
    			var parent = document.getElementById(k+"serial");
    			newSerial.id = "serial_"+k+"_"+eval("count"+k);
    			newComment.id = "comm_"+k+"_"+eval("count"+k);
    			
    			eval("count"+k+"+=1");
    			//eval("dynamic" + i + " = val[i]")
    			
    			parent.appendChild(newSerial);
    			parent.appendChild(newComment);
    			parent.appendChild(newBreak);	
    		}
    function GetSerials() {//data,radioAns) {
    		//THIS ALLOWS FUNCTIONALITY OF indexOF ON IE 
    		if(!Array.indexOf){
    			Array.prototype.indexOf = function(obj){
    				for(var i=0; i<this.length; i++){
    					if(this[i]==obj){
    						return i;
    					}
    				}
    				return -1;
    			}
    		}
    		
    		var counter = count = 0;
    		var k = 1;
    		var serials=[];
    		var comments=[];
    		var counters=[];
    			
    		var elements=document.getElementsByTagName("input");
    		
    		for (var i=0;i<elements.length;i++) 
    		{		
    			if (elements[i].id=="serial_"+k+"_"+counter)
    			{	
    				if(elements[i].className == "size_"+k)
    				{
    					//alert("here");
    					if (serials.indexOf(elements[i].value)==-1)
    					{
    						count++;						
    					} 
    					else 
    					{
    						alert("You can not use duplicate serial numbers - serial number "+elements[i].value+ " repeated");
    						elements[i].style.color = 'red';
    						return;
    					}				
    					counter++;		
    				}
    				k++;
    			}
    		}
    	}
    </script>
    </head>
    <body>
    	<div id="1serial">
    		Serial:	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    				&nbsp;&nbsp;&nbsp;&nbsp;
    				Comment:<br/>
    		<input type="text" id="serial_1_0" class="size_1"/><input type="text" id="comm_1_0"/><br/>
    	</div>
    	<input type="button" value="Add Pipe" onclick="AddInput(1)"><br/>
    			
    	<div id="2serial">
    		<strong>1502 Pipe 2' Joints</strong><br/>
    		Serial:	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    				&nbsp;&nbsp;&nbsp;&nbsp;
    				Comment:<br/>
    		<input type="text" id="serial_2_0" class="size_2"/><input type="text" id="comm_2_0"/><br/>
    	</div>
    	<input type="button" value="Add Pipe" onclick="AddInput(2)"><br/>
    	<!--There are "n" numbers of these-->
    </body>
    </html>
    I have a number of those inputs and at the moment what Im trying to do is to count how many serial numbers of a particular size exists, but I cant seem to wrap my head around it. Thanks for your help.

  2. #2
    Join Date
    Nov 2010
    Posts
    1,276
    let's start with some code that actually works, like I showed you a month ago:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html>
    <head>
    <style type="text/css">
    #serial,#comment{
    float:left;
    }
    #butt{
    clear:both;
    }
    </style>
    
    </head>
    <body>
    <div id="serial">
    Serial:<br><input type="text" class="serials"/>
    </div>
    <div id="comment">
    Comment:<br><input type="text"/>
    </div>
    <div id="butt">
    <input type="button" onclick="checkDupes()" value="Add pipe"/>
    </div>
    <script>
    
    var serials=[];
    function checkDupes(){
    var tbs=document.getElementsByTagName("input");
    serials.length=0;
    for (var i = 0; i < tbs.length; i++) {
    if (tbs[i].type=="text"&&tbs[i].className=="serials"){
    tbs[i].style.color="black"
    if(!Array.indexOf){
    			Array.prototype.indexOf = function(obj){
    				for(var i=0; i<this.length; i++){
    					if(this[i]==obj){
    						return i;
    					}
    				}
    				return -1;
    			}
    		}
    if (serials.indexOf(tbs[i].value)==-1){
    serials.push(tbs[i].value);
    		} else {
    	alert("You can not use duplicate serial numbers - serial number "+tbs[i].value+ " repeated");
    	tbs[i].style.color="red"
    	return;
    			}
    		}
    	}
    var newSerial = document.createElement('input');
    var newComment = document.createElement('input');
    var serBreak = document.createElement('br');
    var comBreak = document.createElement('br')
    newSerial.type = "text";
    newSerial.className = "serials";
    newComment.type = "text";
    var serdiv = document.getElementById("serial");
    var comdiv = document.getElementById("comment");
    newSerial.id = "serial_"+serials.length;
    newComment.id = "comm_"+serials.length;
    serdiv.appendChild(serBreak);
    comdiv.appendChild(comBreak);
    serdiv.appendChild(newSerial);
    comdiv.appendChild(newComment);
    	
    }
    
    
    </script>
    </body>
    </html>
    now what was it that you wanted to do?

  3. #3
    Join Date
    Mar 2012
    Posts
    41
    well this info is going to be sent to a php file. The way this need to be sent is on 3 separate arrays, one with the counts of serials per size. This array will look like 3|2|3|...N.
    The second array will have the size followed by the serials number, and will look like size1|serial1|serial2|serial3|size2|serial1|serial2|sizeN|serialN. The last one will be a collection of all comments whether they exist or not, this will look like com1|com2|com3.
    So i think I am going to use getElementByClassName() to create the arrays of different elements.

  4. #4
    Join Date
    Nov 2010
    Posts
    1,276
    Quote Originally Posted by blak422 View Post
    So i think I am going to use getElementByClassName() to create the arrays of different elements.
    thus excluding anyone using <IE9 from interacting with your database?

    but more importantly, if you have code that prevents users from entering the same serial number, won't the "serials per size" always be 1|1|1?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center

"

"

X vBulletin 4.2.2 Debug Information

  • Page Generation 0.35038 seconds
  • Memory Usage 2,873KB
  • Queries Executed 15 (?)
More Information
Template Usage (34):
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (2)bbcode_code
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (4)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (4)postbit
  • (4)postbit_onlinestatus
  • (4)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (72):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates