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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript + PhP + mysql = Headache, using <select> and Javascript

Status
Not open for further replies.

nightswore

Programmer
Jul 14, 2008
2
US
So, here is my drop down list, the plan is to have it self update the database with its own value when a new one is selected. Basically this is for a status page, as you can tell from the complete/incomplete etc. Anyway it works up to a point; no matter what I select, it takes the value from the bottom "onselect" command and updates with it, rather than the corresponding value. I'll try to promptly answer questions, as I tend to make no sense sometimes.

<select name="bodystatus" id="select" onchange=$_SERVER ['PHP_SELF']>
<option value='N/A' onselect=<? mysql_query("UPDATE `getready` SET `status` = 'N/A'"); ?> >N/A</option>
<option value='waiting' onselect=<? mysql_query("UPDATE `getready` SET `status` = 'Waiting'"); ?> >Waiting</option>
<option value='in progress' onselect=<? mysql_query("UPDATE `getready` SET `status` = 'In Progress'"); ?> >In Progress</option>
<option value='incomplete' onselect=<? mysql_query("UPDATE `getready` SET `status` = 'Incomplete'"); ?> >Incomplete</option>
<option value='complete' onselect=<? mysql_query("UPDATE `getready` SET `status` = 'Complete'"); ?> >Complete</option>
</select>
 
[1] Have you seen through casual browsing any article out there have its option script with onselect event handling? It is not what you imagine, onselect event.
section 18.2.3

[2] Your event handling onselect or onchange do not show you understand server-side vs client-side scripts and mix them all up at wrong time chronology.

[3] This is the rough outline your page should look like. Any missing part of server-side functionality, you should further ask php-forum.
[tt]
<?php
//... etc etc
if (isset($_POST['bodystatus']) && $_POST['bodystatus']!='N/A') {
$result=mysql_query("UPDATE getready SET status = '".$_POST['bodystatus'])."'");
//...etc etc (probably also with re-direction)
}
//... etc etc
?>
<!-- etc etc -->
<form name="xyz" method="POST" action="<? =$_SERVER['PHP_SELF'] ?>">
<!-- etc etc -->
<select name="bodystatus" onchange="this.form.submit();">
<option value='N/A'>N/A</option>
<option value='waiting'>Waiting</option>
<option value='in progress'>In Progress</option>
<option value='incomplete'>Incomplete</option>
<option value='complete'>Complete</option>
</select>
<!-- etc etc -->
</form>
[/tt]
 
tsuji suggests a very slick approach with a downside to it:
"It has to submit the page"

Using AJAX would be a much more attractive solution as the PHP could be executed without submitting forms.

Check out this thread
Here, I posted code snippets to dynamically change combo boxes using XAJAX, a PHP class you can download free of charge. The thread also provides a link where XAJAX can be downloaded.

Good luck!


--
SouthBeach
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top