?
Solved

javascript [object object] message..

Posted on 2013-05-22
9
Medium Priority
?
422 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
How to Create Failover DNS Record Sets in Route 53

Route 53 has the ability to easily configure DNS record sets specifically for failover scenarios. These failover record sets can be configured to failover to full-blown deployments in other regions or to a static HTML page that informs your customers of the issue.

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

764 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