drop down menu

Drop down menu change

Page 1 of 1

8 Replies - 1770 Views - Last Post: 07 January 2010 - 10:00 AM Rate Topic: -----

#1 rwtrwt2003  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 09-June 09

drop down menu

Posted 05 January 2010 - 11:39 AM

Quote

I want to populate a field when the drop down menu changes.
so for an example if the drop down menu changes to 1 then the field next to it needs to be populated with "a" in it.
Here is the Code that i have.


<script type="text/javascript">
var Vendors = new Array();
<?php
		while($row_getVendor = mysql_fetch_assoc($getVendor))
	 	{
		   	print "Vendors['".$row_getVendor['Switch']."'] = '".$row_getVendor['Vendor']."';\n";
		}
	?>
function updateVendor(Switch) //Switch is current value of select box
	{
		if(Vendors[Switch]){
			document.getElementById('Vendor').value =  Vendors[Switch];
		}
		alert(Vendors);
	}
	document.write("<input name=Vendors type=text id=Vendors >");

	</script>
  <?php echo Vendors ?>
[/php]
[php]
 <label><strong>Switch:
	<select name="Switch" id="Switch" onchange="updateVendor(this.options[this.SelectedIndex].value)">
	  <?php
			while ($row_getSwitches = mysql_fetch_assoc($getSwitches))
			{
				print "<option value='".$row_getSwitches['Switch']."'>".$row_getSwitches['Switch']."</option>\n";
			}
		?>
	</select>
	</strong></label>



Quote

I just cant figure out why that when i change the drop down menu that the Vendor field will not populate.


Admin Edit: Please use code tags when posting your code. Code tags are used like so => :code:

Thanks,
PsychoCoder :)

Is This A Good Question/Topic? 0
  • +

Replies To: drop down menu

#2 BenignDesign  Icon User is online

  • holy shitin shishkebobs
  • member icon




Reputation: 6005
  • View blog
  • Posts: 10,428
  • Joined: 28-September 07

Re: drop down menu

Posted 05 January 2010 - 11:45 AM

I would wager your problem lies in that Javascript is a client-side language while PHP is a server-side language. Please, other members correct me if I am mistaken here, but I don't think the two can play together quite the way you want them to.

I would use the javascript to call separate php files to populate the drop-down.

Edit: You've been working on this since August of 2009!?! If you don't mind my asking, why did you stop for so long before coming back to it?

This post has been edited by BenignDesign: 05 January 2010 - 11:51 AM

Was This Post Helpful? 3
  • +
  • -

#3 rwtrwt2003  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 09-June 09

Re: drop down menu

Posted 05 January 2010 - 12:52 PM

View PostBenignDesign, on 5 Jan, 2010 - 10:45 AM, said:

I would wager your problem lies in that Javascript is a client-side language while PHP is a server-side language. Please, other members correct me if I am mistaken here, but I don't think the two can play together quite the way you want them to.

I would use the javascript to call separate php files to populate the drop-down.

Edit: You've been working on this since August of 2009!?! If you don't mind my asking, why did you stop for so long before coming back to it?


Quote

The reason that i stop working on it because got put on another project

Was This Post Helpful? 0
  • +
  • -

#4 rwtrwt2003  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 09-June 09

Re: drop down menu

Posted 05 January 2010 - 03:04 PM

I was doing some test with the web site and i keep getting a error when i change the dropdown this.options[this.SelectedIndex] is undefined
Was This Post Helpful? 0
  • +
  • -

#5 BenignDesign  Icon User is online

  • holy shitin shishkebobs
  • member icon




Reputation: 6005
  • View blog
  • Posts: 10,428
  • Joined: 28-September 07

Re: drop down menu

Posted 05 January 2010 - 07:24 PM

Can I see the code for updateVendor() ?
Was This Post Helpful? 0
  • +
  • -

#6 rwtrwt2003  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 09-June 09

Re: drop down menu

Posted 06 January 2010 - 07:45 AM

View PostBenignDesign, on 5 Jan, 2010 - 06:24 PM, said:

Can I see the code for updateVendor() ?

Quote

here is the code

function updateVendor(Switch) //Switch is current value of select box
	{
		if(Vendors[Switch]){
			document.getElementById('Vendor').value =  Vendors[Switch];
		}
		alert(Vendors);
	}
	document.write("<input name=Vendors type=text id=Vendors >");

	</script>


This post has been edited by rwtrwt2003: 06 January 2010 - 07:46 AM

Was This Post Helpful? 0
  • +
  • -

#7 BenignDesign  Icon User is online

  • holy shitin shishkebobs
  • member icon




Reputation: 6005
  • View blog
  • Posts: 10,428
  • Joined: 28-September 07

Re: drop down menu

Posted 07 January 2010 - 03:38 AM

Are you sure this is a PHP problem and not a Javascript problem?

Are you sure you can use PHP inside the Javascript like that and make it work?
Was This Post Helpful? 0
  • +
  • -

#8 rwtrwt2003  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 09-June 09

Re: drop down menu

Posted 07 January 2010 - 09:34 AM

View PostBenignDesign, on 7 Jan, 2010 - 02:38 AM, said:

Are you sure this is a PHP problem and not a Javascript problem?

Are you sure you can use PHP inside the Javascript like that and make it work?


is there any other way to do it in php that will do the same thing that i am trying to do.
I am up for any suggestions
Was This Post Helpful? 0
  • +
  • -

#9 BenignDesign  Icon User is online

  • holy shitin shishkebobs
  • member icon




Reputation: 6005
  • View blog
  • Posts: 10,428
  • Joined: 28-September 07

Re: drop down menu

Posted 07 January 2010 - 10:00 AM

View PostBenignDesign, on 5 Jan, 2010 - 01:45 PM, said:

I would wager your problem lies in that Javascript is a client-side language while PHP is a server-side language. Please, other members correct me if I am mistaken here, but I don't think the two can play together quite the way you want them to.

I would use the javascript to call separate php files to populate the drop-down.

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1