0

When i press ok button why checkform not return false; ?

Fill image url that dimension less than 500x500px in this case https://pbs.twimg.com/profile_images/839721704163155970/LI_TRk1z_400x400.jpg (400x400 px) Why not return false;

How can i do ?

test1.php

<form class="form" method="post" action="" ENCTYPE = "multipart/form-data" onsubmit="return checkform(this);" >
    <input type="text" id="image_data" name="image_data" value="https://pbs.twimg.com/profile_images/839721704163155970/LI_TRk1z_400x400.jpg">
    <input type="submit" name="submit" value="OK">
</form>

<form id="image_fid">
    <input type="text" name="image_data_url" id="image_data_url"/>
    <input type="text" name="image_data_dimension_width" id="image_data_dimension_width"/>
    <input type="text" name="image_data_dimension_height" id="image_data_dimension_height"/>
</form>
<span id="mySpan_image_fid"></span>

<script language="JavaScript" type="text/javascript">
function checkform ( form )
{
    var image_data_val = document.getElementById("image_data").value;
    document.getElementById("image_data_dimension_width").value = "";
    document.getElementById("image_data_dimension_height").value = "";

    $.ajax
    (
        {
            url: 'test2.php',
            type: 'POST',
            data: $('#image_fid').serialize(),
            cache: false,
            success: function (data) {
                $('#mySpan_image_fid').html(data);
                get_image_data_width_height();
            }
        }
    )
}

function get_image_data_width_height(){
    var image_data_dimension_width_val = document.getElementById("image_data_dimension_width").value;
    var image_data_dimension_height_val = document.getElementById("image_data_dimension_height").value;

    if((image_data_dimension_width_val > '500') && (image_data_dimension_height_val > '500'))
    {
        return true;
    }
    else
    {
        return false;
    }
}
</script>

test2.php

<?PHP
session_start();
include("connect.php");
$image_data_url = mysqli_real_escape_string($db_mysqli,$_POST['image_data_url']);

$image_data_dimension = getimagesize($image_data_url);
$image_data_dimension_width = $image_data_dimension[0];
$image_data_dimension_height = $image_data_dimension[1];
?>

<script>
document.getElementById("image_data_dimension_width").value = "<?PHP echo $image_data_dimension_width; ?>";
document.getElementById("image_data_dimension_height").value = "<?PHP echo $image_data_dimension_height; ?>";
</script>
mamiw
  • 123
  • 4
  • 9
  • Have you checked to see if `image_data_dimension_width_val` is a string of `integer`? I would also remove the single quotes from your comparrison `500` since you want to compare an integer not a string. – NewToJS Nov 23 '17 at 08:41
  • well i dont see `checkform ( form )` returning anything, so yes it wont return `true` or `false` untill you add it there. – Muhammad Omer Aslam Nov 23 '17 at 08:43
  • - Muhammad Omer Aslam return `true` or `false` still in function `get_image_data_width_height` – mamiw Nov 23 '17 at 08:45
  • You check the input as strings, you must do something like this: `if(parseInt(variable) > 500)`. – andeersg Nov 23 '17 at 08:50

0 Answers0