Jump to content

how to pass div content into database


papashoot

Recommended Posts

hi there

 

since i am quite new in ajax and jquery, i like to ask a little help from the expert here.

i have 2 combo box, lets say combo box A and combo box B, and the content of combo box B depends on selected combo box A

it works perfectly

 

the problem is I can pass the content of combo box A into database, but i can't pass the content of combo box B

 

 

here is some code in my php file

<tr>

            <td>Main Fault</td>

            <td >

                <select name="cmbf1" style="width:400px" onChange = "proses_fault()">

                <option value="" selected></option>

                <?php

                  $id_mysql = mysql_connect(SERVER_NAME, USER_NAME, PASSWORD);

                  $db_jualanp1_scenter = mysql_select_db("jualanp1_scenter",$id_mysql);

                  $sql = "SELECT * FROM fault order by fname";

                  $hasil= mysql_query($sql, $id_mysql);

                    while ($baris = mysql_fetch_row($hasil))

                    {

                    $cf1 = $baris[1];

                    print ("<option value = \"$cf1\">$cf1</option>\n");

                    }

                    mysql_close ($id_mysql);

        ?>

                </select>

            </td>

            <td>Main SubFault</td>

            <td colspan="3">

                <div id="datasub" name="cmbfs1"></div>

            </td>

</tr>

 

here is the ajax section

 

function proses_fault()

{

 

  var kode_fault = form.cmbf1.value;

  //if (! kode_fault)

  //  return;

 

  xmlHTTP.open('get', 'getsubfault.php?id_fault=' + kode_fault, true);

  xmlHTTP.onreadystatechange = function ()

  {

      if ((xmlHTTP.readyState == 4))

  {

    document.getElementById("datasub").innerHTML =

    xmlHTTP.responseText;

  }

  }

  xmlHTTP.send(null);

}

 

here is the jquery

<script>

 

$(document).ready(function() {

    $('#submitAsAdd').click(function() {

        var content = $('#datasub').html();

        $.ajax({

            url: 'writefaultsub.php',

            type: 'POST',

            data: {

                content: content

            }

        });

    });

});

 

</script>

 

and here is writefaultsub.php

<?php

 

  require_once "otentik.php";

 

  if (!otentikasi_ok())

  {

    header("Location: login.php?" .

        "pesan=Please Login First");

exit(); 

  }

 

//update trans detail

$vjob = $_SESSION["jobno"];

$id_mysql = mysql_connect(SERVER_NAME, USER_NAME, PASSWORD);

$db_jualanp1_scenter = mysql_select_db("jualanp1_scenter", $id_mysql);

 

$sqlt =  "update transdt set tdfsub1 = '$_POST[content]' where tdjob = '$vjob' "

$hasil = mysql_query ($sqlt, $id_mysql);

 

?>

 

 

can anyone here give me a solution?

thanks in advance  :)

post-135936-13482403722397_thumb.jpg

Link to comment
https://forums.phpfreaks.com/topic/267518-how-to-pass-div-content-into-database/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.