Solved

javascript [object object] message..

Posted on 2013-05-22
9
411 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
 
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Scripting vs. Programming languages 25 117
jQuery Scroll Speed 3 18
update field on focusout 15 24
angularls and plnkr 14 19
This article discusses how to create an extensible mechanism for linked drop downs.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now