Jump to content

PHP AJAX SQL update not working after adding extra record


underlink

Recommended Posts

Not sure how to go about this task but I imagine it requires some sort of foreach loop

 

I have a drop down list populated by a label called LST_Type, this table only exists to provide options for this dropdown list

 

The value selected on the dropdown menu gets written to a table called "assets". when the users clicks away from the form (using ajax)

 

 

Here is what I need to happen:

On page load the dropdown list need its default option to be whatever the current value of the record is in the "asset" table. As the only way you can insert data into this field is via the dropdown list it will always be somethig from the "LST_Type" table

 

The reason is that the data is written to the fields when you click away from the input boxes and unless you are editing the "Type" record it updates it to its default selection.

 

hope this makes sense 

 

here is my code:

<tr id="<?php echo $id; ?>" class="edit_tr">
<!-- Title Colum --><td class="style4"  style="font-size:14px;width:200; height:35px; class="edit_td"> Type: </td>
<td style="font-size:14px;width:270px;border:solid 0px #000;padding:0px; class="edit_td">
<span style="color:#0066CC;" id="type1_<?php echo $id; ?>" class="text"><?php echo $Type; ?></span>



<!-- ***************************************START -  This Is the dropdown menu script *********************************************** -->
 <script type="text/javascript">
    function OnDropDownChange2(dropDown) {
        var selectedValue = dropDown.options[dropDown.selectedIndex].value;
        document.getElementById("type1_input_<?php echo $id; ?>").value = selectedValue;
    }
 </script>
<select name = "MYtype"   id="type1_input_<?php echo $id; ?>" class="editbox"  onChange="OnDropDownChange2(this);">>
<?php
$sql = mysql_query("SELECT Type FROM LST_Type");
while ($row = mysql_fetch_array($sql)){
echo "<option value='" . $row['Type'] . "'>" . $row['Type'] . "</option>";
}
?>
</select>
<input type="text" value="<?php echo $Type; ?>" class="editbox" id="type1_input_<?php echo $id; ?>" /> />
<!-- ***************************************END *********************************************** -->

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.