?
Solved

javascript [object object] message..

Posted on 2013-05-22
9
Medium Priority
?
424 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article will show, step by step, how to integrate R code into a R Sweave document
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

649 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