ajax auto checkbox

Posted on 2009-05-22
Medium Priority
Last Modified: 2012-06-27

i have a select box with some options in and i want to be able to have my ajax replace the value in the options with a value i get from the upload.php

if i use this in the function

document.getElementById(transmission').options[1] = new Option  ('some value');

it replaces it but i need it to replace it with the value in the php page where it reads
echo "formObj.transmission.value = '".$transmission."';\n";  

how would i read that value and put it in this

document.getElementById(transmission').options[1] = new Option  ('$transmission');



what shows in my upload.php that the ajax calls
$transmission = 'Leather Seats';
echo "formObj.transmission.value = '".$transmission."';\n";  
my head section
<script type="text/javascript">
		var ajax = new sack();
	var currentvinId=false;
function getvinData()
document.getElementById('transmission').options.value = getvinData;
		var vin = document.getElementById('vin').value;
			currentvinId = vin
			ajax.requestFile = 'upload.php?getvinId='+vin;	// Specifying which file to get
			ajax.onCompletion = showvinData;	// Specify function that will be executed after file has been found
			ajax.runAJAX();		// Execute AJAX function			
	function showvinData()
		var formObj = document.forms['addlisting'];	
	function initFormEvents()
		document.getElementById('vin').onblur = getvinData;
	window.onload = initFormEvents;
body section
<select id="transmission" name="transmission" size="1"><option value="Automatic">Automatic</option><option value="Manual">Manual</option><option value="Dual">Dual</option></select>

Open in new window

Question by:petecrane99
  • 2
  • 2
LVL 58

Expert Comment

ID: 24455102
The way you are doing it now, it would be done by changing

echo "formObj.transmission.value = '".$transmission."';\n";  

in the php file to

echo "document.getElementById(transmission').options[1] = new Option  ('" . $transmission . "');"

Author Comment

ID: 24455605


i used

echo "formObj.transmission.options[0] = new Option  ('".$transmission."');\n";

and that worked which is great how easy would it be to do with check boxes?

Author Comment

ID: 24457654
this is my checkbox's

<input value="Leather Seats" id="standfeatures" name="standfeatures[8]" type="checkbox">Leather Seats</td>
LVL 58

Accepted Solution

amit_g earned 500 total points
ID: 24458456
Same thing. The php is generating a javascript code line that is executed on the client browser. So you wanted to have a javascript

document.getElementById('transmission').options[1] = new Option  ('some value');

and the php code had

echo "formObj.transmission.options[0] = new Option  ('".$transmission."');\n";

Similarly, it can be done for any other javascript code that you want. So for checkbox assuming that you have unique id, you would need

document.getElementById('standfeatures').checked = true;

in php just echo the above string. But if you don't have unique id (standfeatures) and want to loop through the set of checkboxes, the code would be different. If you give more details, we can help you in that too.
LVL 16

Expert Comment

by:CWS (haripriya)
ID: 37212340
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
AngularJS web development a very simple procedure. So, to put it, in short, AngularJS’ stand out features are – Two-way data binding, MVC structure, directives, templates, dependency injections and testing.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

586 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