1

I need pass variable “idlaw” to base.js and then from base.js to PHP page edit.php

editarLegislacao.php

<input class='btn btn-primary buttonBlue' type='button' name='btnAceitarPend' value='Edit' onClick="javascript:openAreaLaw('editLegislation', 'editlaw','<?php echo $law["idLaw"]?>')"/>

Base.js

function openAreaLaw(closeArea, openArea) {
    if ($("#" + openArea).css('display') == 'block')
        return;
    if(openArea=='applicableLegislation'){
        window.location='maps1.php';
        return;
    }
    if(openArea=='editlaw'){
      $.post({
        url: "views/editarLei.php",
            data: {
                idLaw: $("#idLaw").val()
            },
            async: true,
            success: function () {
            }
        });
    }  

    $("#" + closeArea).stop().fadeOut(500);
    setTimeout(function () {
        $("#" + openArea).stop().fadeIn(500);
    }, 504);
}

Edit.php

if( isset( $_POST['idLaw'] ) ) {
    $idLaw1 = $_POST['idLaw'];
}
4
  • Is there a particular reason why you dont use session or even cookies for this?` Commented Nov 21, 2017 at 15:23
  • Your PHP if is doing the exact opposite of what you're trying to do. Just invert your comparators. Commented Nov 21, 2017 at 15:24
  • i using sessions but i don't need this case Commented Nov 21, 2017 at 15:27
  • i think the jquery is fine but the next php file don´t obtain the value Commented Nov 21, 2017 at 16:05

3 Answers 3

1

Try this code (corrected if condition and removed space in POST)

if(array_key_exists("idLegislacao", $_POST)) {
    $idLei = $_POST["idLegislacao"];
}
Sign up to request clarification or add additional context in comments.

Comments

0

Try with this $idLei = filter_input(INPUT_POST, 'idLegislacao');

Comments

0

There's nothing wrong with your jQuery, it's your PHP that needs tweaking:

if( isset( $_POST['idLegislacao'] ) ) {
    $idLei = $_POST['idLegislacao'];
}

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.