Solved

javascript [object object] message..

Posted on 2013-05-22
9
412 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
DevOps Toolchain Recommendations

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

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn how to count occurrences of each item in an array.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

920 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

17 Experts available now in Live!

Get 1:1 Help Now