Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cobmo Box / URL Variable / Update Form

Status
Not open for further replies.

grobermatica

Programmer
Jul 26, 2006
16
GB
I have a form which updates records, some of the field in the update form are combo boxes and the second one is dynamically dependant on the first one. I have another combo box at the top of the form in which you select the record you want to edit. This populates a url variable which is the record ID.

My problem is this, I need the 2 dependant combo boxes to populate correctly when the record is selected.

I would usually use another URL variable but I can't work out how to populate it.

Having previously used MS Access I would normally use a DLookup function and have found a custom PHP function on the web and use the value in the query:

Code:
function DLookup($fld, $tab, $whr)
{
	$q = "Select $fld from $tab where $whr";
	$rst = mysql_query($q);	
	if ($row = mysql_fetch_object($rst)) 
		return $row->$fld;
	else
		return NULL;
}

This works but is always a record late... so If I select a record to edit... the value plugged into the query is 0, but the real value may be 1, and then if I choose another record, it uses the 1 from the previous request but the actual value may be 2... hope I've explained that well enough.

I need it all to happen in one go so when I select the record the dependant combo boxes populate with the dependant data.

Any ideas / suggestions would be welcome

Many thanks


Craig
 
This populates a url variable which is the record ID.

You mean mean something like: [red]myvar='somevalue'[/red] ?


If so it sounds like your problem is likely whatever is populating that variable (I would guess its Javascript).

Not sure what your function has do with any of this, as it basically just runs a query and returns a row. nothing there that shows drop downs, or other form controls or anything that would populate a url variable.

I really don't quite understand what is happening, perhaps you could show us the code that populates the url variable? and then how you perform the edit of the record.




----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
HI Phil,

Thanks for replying, I apologise if I was not clear what I was trying to achieve. The form is generated by the Adobe Dreamweaver Developer Toolbox as is the javascript function which updates the URL, which is:

Code:
function MM_jumpMenu(targ,selObj,restore,salon){ //v3.0
  eval(targ+".location='editPriceList.php?salon_id="+salon+"&prod_id="+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

the function is called via the onChange property of the main combo box which selects the record to edit. I have added the 'salon' variable myself which is the one I need to set. The prod_id variable is being set correctly and I can use this to find out the salon variable. As I said I would normally use a DLookup function as per my previous post.

Many thanks


Craig
 
I think this comes down to basically an environment issue if I'm understanding this correctly.

You want to execute a PHP function (the Dslookup function) at the moment the dropdown value is chosen so you can generate the correct salon value. However, Javascript and PHP run at different locations and moments. That is when Javascript is running on the client (browser) the onChange event there is no PHP running (because it runs on the sever) so no salon variable can be set.

I would guess that what happens is that PHP runs when the form is submitted and executes the Dslookup function that then it populates the salon variable to the value you want. Except that as you said its late because it uses the old vale form prod_id.

You would need to use Ajax to call upon the PHP Dslookup function to get the value back from it to populate the variable in the OnChange event.

The guys over at the forum1600 may be able to help.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top