0

Currently I have a PHP file and a .js file. In my PHP file I have div class called wrapper_tab-content. Now the code for this is present in my js file which shows the following code:

$(document).ready(function() {
    portalarray = new Array();
    $('input.checkbox').change(function(){
        portalname = $(this).attr('data-name'); pid= $(this).attr('id');
        
        if ($(this).is(':checked')) {
            portalarray.push(pid);
            $(".wrapper_tab-content").append('<div class="portalcontent content--active" id="'+pid+'"><div class="col-md-12 text-left">
            <label class="control-labels ">Title</label><input id="'+pid+'" name="'+portalname+'" placeholder="'+portalname+' Title" type="text"></div></div>');
        }else {
            $(".portaltabs .container--tabs li#"+pid).remove();
            $(".wrapper_tab-content #"+pid).remove();
            tabslength = $(".wrapper_tab-content").length;
        }
    });
});

Now I have to enter the property title inside value attribute that I can get by using <?php get_portals[0]['property_title'] ?> inside my .js file for which I'm assuming there needs to be an AJAX call being made?

1 Answer 1

1

To clear things up for you Javascript is client side and PHP is server side .

What you looking at doing is getting PHP value's into Javascript .There are a few ways to do this . Most programmers use events as server side could have updated during the lifetime of the page

most common is post and get requests through Ajax but you could also get data through an event

<script type='text/javascript'>

document.body.onclick(function(){
    var Variable = <?php echo(json_encode($Variable)); ?>;
};

</script>
Sign up to request clarification or add additional context in comments.

1 Comment

Okay so I post the following code in my View class?

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.