3

Everything almost works! i just need to find out why the code below won't give me more than the first buttons values.

public static function getProjectOnSearch($inp){
        return DB::table('projecten')
            ->select(DB::raw('titel,status,prioriteit,soort,projectnaam,projecturl
            ,gebruikersnaam,wachtwoord
            ,gebruiker_id,omschrijvingproject'))
            ->where('projectnaam', 'LIKE', '%'.$inp.'%')
            ->get();
    }

enter image description hereI want to fill in some input fields with values from my database upon clicking an button. I have the code working to fill in an name and click on the search button to fill the inputs. That works great. When I use that code with the other button it won't work. see my code below.

Javascript code :

<script type="text/javascript">
    $("#wijzigKnop2").on("click",function(){
      var email2 = $('#zoeknaam2').val('');
      $('#titel2').val('');
      $('#status2').val('');
      $('#prioriteit2').val('');
      $('#type2').val('');
      $('#projectnaam2').val('');
      $('#projecturl2').val('');
      $('#gebruikersnaam2').val('');
      $('#wachtwoord2').val('');
      $('#omschrijving2').val('');

      $.ajax({
        method: "POST",
        url: "/updateProjectData",
        data: {   input: email2 ,
               _token: "{{ csrf_token() }}"
              }
      })
        .done(function( msg ) {
        $('#titel2').val(msg[0].titel);
        $('#status2').val(msg[0].status);
        $('#prioriteit2').val(msg[0].prioriteit);
        $('#soort2').val(msg[0].soort);
        $('#projectnaam2').val(msg[0].projectnaam);
        $('#projecturl2').val(msg[0].projecturl);
        $('#gebruikersnaam2').val(msg[0].gebruikersnaam);
        $('#wachtwoord2').val(msg[0].wachtwoord);
        $('#omschrijving2').val(msg[0].omschrijvingproject);
      });

    });
</script>

HTML Button with hidden input for value (normally the value would be typed in but this button will get the value from an HTML table which generates a row throught a foreach)

   <input type="hidden" value="{{$project->projectnaam}}" 
id="zoeknaam2" name="zoeknaam2" class="form-control" placeholder="Projectnaam">

<button class="btn btn-success btn-xs" id="wijzigKnop2" name="zoekProject" type="button">
<i class="glyphicon glyphicon-pencil"></i>
</button>

Any answers or ideas are very welcome thanks in advance for posting!

21
  • 1
    were your code get failed? Commented Dec 14, 2015 at 13:14
  • 1
    Please check your posted data is correctly passed to ajax. Commented Dec 14, 2015 at 13:15
  • 1
    Please look into your browser console to check the ajax output Commented Dec 14, 2015 at 13:18
  • 1
    Is your ajax request not send?? then problem with data sended to ajax. Commented Dec 14, 2015 at 13:21
  • 1
    Have you check the value of msg? is it have something. check it in console. Commented Dec 14, 2015 at 13:24

2 Answers 2

1

Please check

var email2 = $('#zoeknaam2').val('');

this should be not blank

var email2 = $('#zoeknaam2').val();

If you get proper value in at server side then problem at server side code.

To check on response,do

console.log(JSON.stringify(msg));

As per questioner server side solving

public static function getProjectOnSearch($inp){
    return DB::table('projecten')         ->select(DB::raw('titel,status,prioriteit,soort,projectnaam,projecturl ,gebruikersnaam,wachtwoord ,gebruiker_id,omschrijvingproject')) ->where('projectnaam', 'LIKE', '%'.$inp.'%') ->get(); 
}

fixes all things.

Sign up to request clarification or add additional context in comments.

2 Comments

helped a bit. need to fix my php code : public static function getProjectOnSearch($inp){ return DB::table('projecten') ->select(DB::raw('titel,status,prioriteit,soort,projectnaam,projecturl ,gebruikersnaam,wachtwoord ,gebruiker_id,omschrijvingproject')) ->where('projectnaam', 'LIKE', '%'.$inp.'%') ->get(); }
you need to search record by 'id' as you want it for edit purpose.
0

Get the value of the element then clear it.

var email2 = $('#zoeknaam2').val();
$('#zoeknaam2').val('');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.