Solved

javascript [object object] message..

Posted on 2013-05-22
9
415 Views
Last Modified: 2013-06-11
How can I get all the input values in a form into an array?

form
0
Comment
Question by:Isaac
9 Comments
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 39189044
x=document.getElementsByTagName('input');

will create an array of all the input element objects.

then the values could be accessed with x.value[0] ... x.value[n];

Cd&
0
 
LVL 44

Expert Comment

by:Rainer Jeschor
ID: 39189290
Hi,
you had a similar question with source code which you have deleted. As I was heavily working on your other question I could not respond in a timely manner.
Could you please post the code again?
The issue is that as far as I have seen on the list screenshot, you will have to create two items in the SharePoint list - one for each FY.
HTH
Rainer
0
 
LVL 5

Author Comment

by:Isaac
ID: 39189374
I'm sorry...I thought no one understood the question.  Here you go....

<table id="initiative" border="1" width="65%">
<tr>
	<td></td>
</tr>
</table>

<Div id="xData"></div>
<script type="text/javascript" src="https://****.****s/jquery-1.8.2.min.js" language="javascript"></script>
<script type="text/javascript" src="https://****.****s/jquery.SPServices-0.7.2.min.js" language="javascript"></script>
<script type="text/javascript" src="https://****.****s/jquery-ui-LatestVersion.js" language="javascript"></script>

<script type="text/javascript">
var MeasuresIndexArray = new Array();
var FY13Array = new Array();
var FY14Array = new Array();
$(document).ready(function() {
currSiteUrl = $().SPServices.SPGetCurrentSite();
 
var soapEnv3 =
        "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'>" +
            "<soapenv:Body>" +
                "<GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'>" +
                    "<listName>Objective Level Performance Measures</listName>" +
					"<query><Query><Where><Eq><FieldRef Name='Title' /><Value Type='Text'>1.1.1M</Value></Eq></Where></Query></query>" +
                    "<viewFields>" +
                        "<ViewFields>" +
                        "</ViewFields>" +
                    "</viewFields>" +
                "</GetListItems>" +
            "</soapenv:Body>" +
        "</soapenv:Envelope>";
        $.ajax(
	{
	    url: currSiteUrl + "/_vti_bin/lists.asmx",
	    async: true,
	    type: "POST",
	    dataType: "xml",
	    data: soapEnv3,
	    complete: GetCurrentResult,
	    contentType: "text/xml; charset=\"utf-8\""
	});	
});


	function GetCurrentResult(xData, status) {
		var currentYear = (new Date).getFullYear();
		alert(xData.responseXML.xml);
		$("#xData").append(xData);
		//Iterates through each row and returns information - Populates the "Performer" dropdown with values from the Objectives list
		var i = 0;
		$(xData.responseXML).find("z\\:row").each(function() {  
			//This decides how many input boxes to provide
			//alert("Index: "+$(this).attr("ows_LRECMeasuresIndex").split(","));
			var MeasureIndex = $(this).attr("ows_LRECMeasuresIndex").split(",");
			
			$.each(MeasureIndex, function(index, value){
				MeasuresIndexArray[i] = value;			
				i++;
			});
			
			var inititativeMeasure = $(this).attr("ows_Title");
			var LongDescription = $(this).attr("ows_LongDescription");
			var ReportingFrequency = $(this).attr("ows_ReportingFrequency");
			$("#initiative").append("<tr><td colspan='2'><input type='hidden' value="+inititativeMeasure+" id='measure'><ip</td></tr>");
			$("#initiative").append("<tr><td>"+inititativeMeasure+"</td><td>"+LongDescription+"</td></tr><tr><td>Frequency of Calculation:</td><td>"+ReportingFrequency+"</td></tr><tr><td colspan='2'>Please provide 'Current Result' for each quarter of each Fiscal Year.</td></tr>");
			if (ReportingFrequency=="Quarterly")
			{
				var qtrInput = 4;
				var nextYear = currentYear+1;
				currentResultYear(qtrInput,currentYear);
			}
			else if (ReportingFrequency=="Annual")
			{
				var qtrInput = 1;
				var nextYear = currentYear+1;
				currentResultYear(qtrInput,currentYear);
			}		
	});
	$("#initiative").append("<tr><td colspan='2'><input type='submit' id='SubmitButton' value='Submit' onclick='SubmitButtonClick(this)'></td></tr>");
			
	}
	
	function currentResultYear(qtrInput,Year)
	{
			var j=1;			
			
			var aryCnt = MeasuresIndexArray.length;
			//alert("indexcnt: "+aryCnt);
			if (qtrInput > 1)
			{
				$.each(MeasuresIndexArray, function(index, value){
				alert("Fiscal: "+value);
					for(var i = 0; i < qtrInput; i++)
						{							
							$("#initiative").append("<tr><td colspan='2'>"+MeasuresIndexArray[index]+" Qtr"+j+"<input type='text' value='' id='CurrentResult"+MeasuresIndexArray[index]+"Qtr"+j+"' /></td></tr>");//<input name="CurrentResultFY13Qtr1"/>
							
							alert("val: "+value);
							alert("measureYrQtr: "+$("#CurrentResult"+MeasuresIndexArray[index]+"Qtr"+j));							
							if (value=="FY13")
							{
							  alert("i: "+i);
						      FY13Array[i] = $("#CurrentResult"+MeasuresIndexArray[index]+"Qtr"+j).val();
							  alert(FY13Array[i]);
							}
							else if (value=="FY14")
							{
							  FY14Array[i] = $("#CurrentResult"+MeasuresIndexArray[index]+"Qtr"+j).val();
							}
							j++;
						}
						$("#initiative").append("<tr><td colspan='2'>&nbsp;</td></tr>");
						j=1;					
				});	
				
			}			
	}	
	
	function SubmitButtonClick(element)
	{
		alert("HELLO");
		alert(element);
		
	
		
	/*	$.each(FY13Array, function(index, value){
			alert("FY13 Array: "+FY13Array[index]);
		});
		*/
		
		/*$().SPServices(
				{
					operation: "UpdateListItems",
					listName: "CurrentResultList",
					async: false,					
					updates: "<Batch OnError='Continue' PreCalc='TRUE'>" +
						"<Method ID='1' Cmd='New'>" +
							"<Field Name='Title'>"+$("#measure").val()+"</Field>" +
							"<Field Name='CurrentResultQtr1'>" + $("#drpdActivity").val() + "</Field>" +
							"<Field Name='CurrentResultQtr2'>" + $("#drpdAotDesignator").val() + "</Field>" +
							"<Field Name='CurrentResultQtr3'>" + $("#CompletionDate").val() + "</Field>" +
							"<Field Name='CurrentResultQtr4'>" + $("#drpdContract").val() + "</Field>" +		
							"<Field Name='FiscalYear'>" + $("#drpdContract").val() + "</Field>" +							
						"</Method>" +
					"</Batch>",
					completefunc: function(xData, Status) 
					{
						//SaveRisks();
					}	
				});*/
	}
</script>

Open in new window


(Edit: Redacted - Modulus_Twelve, mplungjan)
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 39189788
All input elements in a form are already in the collection of document.formName.elements
However seeing you are using jquery you should use


$("form :input").each(function(){
    $(this).....
});

COBOL: you code would miss select and textarea
0
 
LVL 5

Author Comment

by:Isaac
ID: 39197625
Hi, what if I just wanted the text fields?  Would it be $("$form:text").each.........?
0
 
LVL 5

Author Comment

by:Isaac
ID: 39197629
Because the code is dynamic, I would also like to grab the id name of the text element and not just the value. How can I do that?  Thx!
0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 500 total points
ID: 39197675
$("form :text").each(function(){
  alert(this.id+":"+this.value)
});
0
 
LVL 5

Author Comment

by:Isaac
ID: 39197710
mplungjan,

That worked to get the value. Thanks!

 Any idea, how I can get just the "id" name of the element.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 39198490
this.id is the ID this.name is the name...
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Problem to refer to value 8 49
javascript: add id amounts 5 47
Best Way to remove the port from a URL? 15 36
replace link with jQuery 4 14
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
This article discusses how to create an extensible mechanism for linked drop downs.
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question