0

Why my button javascript doesnt work? is this bcause textarea?? or because I was too stupid and made some mistakes,,,

(when i click button, nothing hapen,,, data not save to db,, the error did not appear,,)

    <script type="text/javascript">
    $(document).ready(function() {
            $("#save_data").click(function() {
                    var date        = $('#datetimepicker1').val();
                    var sdlc        = $('#sdlc').val();
                    $.ajax({
                        type: "POST",
                        url: "modul/update.php",
                        data:   "date="+date+
                                "&sdlc="+sdlc,
                                
                        success: function(data) {
                            alert('Berhasil di input');
                            window.location.href='p.php?p=uFA'
                        }
                        error: function(data) {
                            alert('gagal di input');
                            window.location.href='p.php?p=uFA'
                        }
                    });

                });
    });     
</script>

this is my input form

<input id="datetimepicker1" type="text" value="<?php echo date('Y-m-d');?>" data-date-format="YYYY-MM-DD" class="input-sm" />
<textarea style=" resize: vertical;" id="sdlc" name="sdlc" rows="4" cols="70%" > </textarea>
<button class="btn btn-primary btn-rounded pull-right" id="save_data" name="save_data"><i class="fa fa-save"></i> save </button>

and this update.php

$date       =$_POST['date'];
$sdlc       =$_POST['sdlc'];
$input = "INSERT INTO table
(id,date,sdlc)  VALUES('','$date','$sdlc')";
    mysql_query($input);

thanks 4 everything

  • 2
    What do you mean "don't work"? function click don't work, or function work and can't do as you want? – Trần Hữu Hiền Sep 18 '20 at 03:19
  • nothing hapen,,, data not save,, the error did not appear,, – Mitsuky Roku Sep 18 '20 at 03:20
  • 2
    Something happens. You need to tell us where in the sequence it goes wrong by doing basic debugging. Does click event fire? Is request made? Any errors? If request is made what is it's status? Is there a `
    ` and you aren't preventing default submit and page reloads? etc etc
    – charlietfl Sep 18 '20 at 03:25
  • I didn't create
    because I thought I didn't need a form when using js I press the click button and the button turns thick on the side which indicates if the button works, In javascript there are successes and errors but the two alerts don't appear, when I check the db, no data is added yet ..
    – Mitsuky Roku Sep 18 '20 at 03:32

1 Answers1

2

You've missed a , in your javascript code, after success function. Here is the fixed javascript code:

$(document).ready(function() {
        $("#save_data").click(function() {
                var date        = $('#datetimepicker1').val();
                var sdlc        = $('#sdlc').val();
                $.ajax({
                    type: "POST",
                    url: "modul/update.php",
                    data:   "date="+date+
                            "&sdlc="+sdlc,
                            
                    success: function(data) {
                        alert('Berhasil di input');
                        window.location.href='p.php?p=uFA'
                    },
                    error: function(data) {
                        alert('gagal di input');
                        window.location.href='p.php?p=uFA'
                    }
                });

            });
});
Dharman
  • 30,962
  • 25
  • 85
  • 135