0

pass dynamic values in json data in java script means when i am changing combo box i want to store values from combo box to json in key -value pair and finally also want length of JSON
anyone please help me ......
Here is my code

<script type="text/javascript">
	var graphArray =new Object();
	function changeConcentration()
	{
		 substance=$("#substance").val();
		 concentration=$("#concentration").val();
		 ans = substance*concentration;			
	}
	function calculateMeasurement()
	{ 
		var a=0;
		if($("#answer").val()==ans)
			{
					
				graphArray={ "concentration" : concentration,"answers" : ans }; //my json
				
						
		 		if(graphArray.length>=6)
		 		{
					//some task to be done
		 		}
		 	}		 
	}
	
		
</script>
</head>
<body>
		
			<table border="0" align ="left">
			
				<tr><td>Substance</td><td>:</td>
					<td>
						<select id="substance">
							 <option>Select</option>
							  <option>2</option>
							  <option>3</option>
							  <option>4</option>
						</select>
					</td>
				</tr>
				<tr><td>Concentration</td><td>:</td>
					<td><select id="concentration" onChange="changeConcentration();">
							  <option>Select</option>
							  <option>5</option>
							  <option>10</option>
							  <option>30</option>
						</select>
					</td>
				</tr>
				<tr><td>Cell Constant</td><td>:</td>
				<td><select name="cell_constance">
							  <option>Select</option>
							  <option>10.0</option>
					</select>
				</td></tr>
				<tr><td>Specific Conductance at 250C</td><td>:</td><td><input id="answer" type="text" name="answer"></td></tr>
				<tr><td></td><td></td><td><input type="Submit" value="Submit" onclick="calculateMeasurement()"/></td></tr>
			</table>				
		
</body>
</html>

Edited by Pravinrasal: n/a

2
Contributors
1
Reply
4
Views
5 Years
Discussion Span
Last Post by AleMonteiro
0

Pravinrasal,

if you want the length, you need to use an array.

//Create array
var graphArray =new Array();
// Add item to array
graphArray.push({ "concentration" : concentration,"answers" : ans });
// Alert array length
alert(graphArray.length);

But your code has some problems, for example: the options has no value, so the changeConcentration() function is not working.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.