Page 1 of 1

Form selection fills out textarea's based on mysql db...

Posted: Sat Apr 15, 2006 9:36 am
by tony584
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


hello all, been racking my brains on this one decided to finally chuck it up to the higher powers...

I have a SELECT form object that is filled by the name and address of elements in a database table.
When I SELECT one of these names & addresses, I want 3 corresponding textfields to be filled with more detailed information than just the name and address. The other information is vendor_number, sc_number, and brc_number. 

Heres my snippet:

Code: Select all

<SELECT ONCHANGE="this.form.vendor_number.value = ?????; 
			            this.form.sc_number.value         = ?????; 
				    this.form.brc_number.value       = ?????;">
<?php
       $grab="SELECT * FROM vendor_table";
       $result = mysql_query($grab);

        print(" <OPTION SELECTED VALUE=\"00\">&mdash; Select a Vendor &mdash;\n");

		
       while($row = mysql_fetch_array($result))
       {
          print(" <OPTION VALUE=$row[vid]>$row[name]\n,$row[address]\n");
		
       }
        print(" </SELECT>\n"); ?>

Thanks, help would be wonderful. I've tried putting the values into an array in the loop then putting them up in onChange, that doesnt work, I tried doing mysql queries in the onChange part, that didnt work. Totally clueless.

-have a good one, Tony


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Sat Apr 15, 2006 9:57 am
by feyd
You could store the extra data in the value attribute of the option. This can be accomplished by using the Javascript string method called split, that functions much like explode()

Posted: Sat Apr 15, 2006 10:19 am
by tony584
once i concatenate the items,
they have a period "." between them.
i still cannot figure out how to split them and send the appropriate part to the appropriate text field in the on Change section.

by the way thanks for the formatting help.
cheers,
tony

Posted: Sat Apr 15, 2006 10:25 am
by feyd
what does it look like right now?

Posted: Sat Apr 15, 2006 10:41 am
by tony584
So far I have:

Code: Select all

<?php
       print(" <OPTION SELECTED VALUE=\"00\">&mdash; Select a Vendor &mdash;\n");	
       while($row = mysql_fetch_array($result))
       {
          // Concatenates all of my required info into VALUE field.
          print(" <OPTION VALUE=$row[vnumber].$row[vid].$row[sc_number].$row[brc_number]>$row[name]\n,$row[address]\n");	
       }
        print(" </SELECT>\n"); 
       ?>
So, my onChange would be:

Code: Select all

<SELECT ONCHANGE="split_and_display(this.value)"> //this would send my value to split_and_display
So when i get to writing split and display...

I would use something like the following... its where i get stuck...

Code: Select all

function split_and_display(this)
{
var mytool_array=this.split(".");  //splits this.value at periods
this.form.vendor_number.value = mytool_array[0]; 
this.form.sc_number.value     = mytool_array[1]; 
this.form.brc_number.value    = mytool_array[2];
}
Thanks!

Posted: Sat Apr 15, 2006 10:52 am
by feyd
Try this

Code: Select all

<?php
	print(" <OPTION SELECTED VALUE=\"00\">&mdash; Select a Vendor &mdash;\n");
	while($row = mysql_fetch_array($result))
	{
		// Concatenates all of my required info into VALUE field.
		print(" <OPTION VALUE=\"$row[vnumber].$row[vid].$row[sc_number].$row[brc_number]\">$row[name]\n,$row[address]\n</OPTION>");
	}
	print(" </SELECT>\n");
?>

Code: Select all

<SELECT ONCHANGE="split_and_display(this.form, this.options[this.selectedIndex].value)"> //this would send my value to split_and_display

Code: Select all

function split_and_display(frm, value)
{
	if(value != '00')
	{
		var mytool_array=value.split('.');  //splits this.value at periods
		frm.elements['vendor_number'].value = mytool_array[0]; 
		frm.elements['sc_number'].value     = mytool_array[1]; 
		frm.elements['brc_number'].value    = mytool_array[2];
	}
}

Posted: Sat Apr 15, 2006 11:18 am
by tony584
thanks! pure genius!
works smoothly...

http://elvis.rowan.edu/~gebely74/entry_with_vend.php