We help IT Professionals succeed at work.
Get Started
Troubleshooting Question

Going from hard-coded to a variable

David Schure
David Schure asked
on
66 Views
Last Modified: 2020-11-24
I have javascript that is hard-coded with an ID   I need to change that to a variable to pass to a modal...
The script  problem is in bold  data : { id : 3 },
 $.ajax({
      url: 'CLIENT/insert-answers.php',
        type: 'POST',
        data : dataObject,
        success: function(response) {
                console.log(response);
                $.ajax({
                    url : 'MODALPHP.php',
                    data : { id : 3 },
                })
                .done(function(resp) {
                    $('#myTherapist .modal-title').html(resp.title)
                    $('#myTherapist .modal-body').html(resp.html)
                    $('#myTherapist').modal({show:true})
I need this to be...
 data : { id : $client_id },
Which comes from this.
function submitAnswers() {
    let dataObject = {
        'client_id' : $('#client_id').val(),
      'tcountry' : document.tcountryq.tcountry.value,
        'state' : document.stateq.state.value,
      'type' : document.typeq.type.value,
        'reasons' : document.reasonsq.reasons.value,
        'gender' : document.genderq.gender.value,
      'tgender' : document.tgenderq.tgender.value,
        'age' : document.ageq.age.value,
        'sex' : document.sexq.sex.value,
      'relationship': document.relationshipq.relationship.value,
        'religious': document.religiousq.religious.value,
      'spiritual' : document.spiritualq.spiritual.value,
      'counsel' : document.counselq.counsel.value,
        'corona' : document.coronaq.corona.value,
        'suicide' : document.suicideq.suicide.value,
        'panic' : document.panicq.panic.value,
        'medication' : document.medicationq.medication.value,
        'pain' : document.painq.pain.value,
        'finance' : document.financeq.finance.value,
        'sleep' : document.sleepq.sleep.value,
        'refer' : document.referq.refer.value,
    }
    
    $('#severalquestions').modal('hide');

    $.ajax({
      url: 'CLIENT/insert-answers.php',
        type: 'POST',
        data : dataObject,
        success: function(response) {
                console.log(response);
                $.ajax({
                    url : 'MODALPHP.php',
                    data : { id : 3 },
                })
                .done(function(resp) {
                    $('#myTherapist .modal-title').html(resp.title)
                    $('#myTherapist .modal-body').html(resp.html)
                    $('#myTherapist').modal({show:true})
                })
          }, error: function (jqXHR, exception) {
                var msg = '';
                if (jqXHR.status === 0) {
                    msg = 'Not connect.\n Verify Network.';
                } else if (jqXHR.status == 404) {
                    msg = 'Requested page not found. [404]';
                } else if (jqXHR.status == 500) {
                    msg = 'Internal Server Error [500].';
                } else if (exception === 'parsererror') {
                    msg = 'Requested JSON parse failed.';
                } else if (exception === 'timeout') {
                    msg = 'Time out error.';
                } else if (exception === 'abort') {
                    msg = 'Ajax request aborted.';
                } else {
                    msg = 'Uncaught Error.\n' + jqXHR.responseText;
                }
                alert(msg);
            },
        });
        return false;
   }
I need the client-id to be on the MODALPHP.php modal so that I can run an insert query on that modal.  But first I need to get the client_id over there.
Comment
Watch Question
CERTIFIED EXPERT
Most Valuable Expert 2020
Most Valuable Expert 2018
Commented:
This problem has been solved!
Unlock 1 Answer and 40 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant

An Experts Exchange subscription includes unlimited access to online courses.

Get Started
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE