1

My HTML is -

<input type="submit" onclick="javascript:agreeprint();" value="Proceed">

And my JavaScript function is -

<script type="text/javascript">
    function agreeprint()
    {
        if($("#company").val()==''||$("#office_address").val()=='')
        {
            alert('<?php echo $this->translate('Please enter the empty field values'); ?>');
            return false;
        }
        else
        {
            var companyval  = $("#company").val();
            var officeaddrval = $("#office_address").val();
            $.ajax({
                type: "POST",
                url: "/index/agreement",
                data: $( "form" ).serialize(),
                success: function(msg){
                    if(msg.substr(0,9)=='contratt_')
                    location.href = '/filename/'+msg;
                }
            }); 
        }

        window.location = "/index";   //The redirection is not working
    }
</script>

After the function is finished the redirection process does not happened. What am I doing wrong?

Sundhar Ji
  • 15
  • 4

1 Answers1

1

There is nothing wrong with the redirection because I ran jun the redirection part of your code,

<script type="text/javascript">
function agreeprint()
{
    window.location = "/index";   //The redirection is not working
}
</script>

<input type="submit" onclick="javascript:agreeprint();" value="Proceed">

and it works perfectly. There must be something wrong with the javascript before the redirection:

if($("#company").val()==''||$("#office_address").val()=='')
    {
        alert('<?php echo $this->translate('Please enter the empty field values'); ?>');
        return false;
    }
    else
    {
        var companyval  = $("#company").val();
        var officeaddrval = $("#office_address").val();
        $.ajax({
            type: "POST",
            url: "/index/agreement",
            data: $( "form" ).serialize(),
            success: function(msg){
                if(msg.substr(0,9)=='contratt_')
                location.href = '/filename/'+msg;
            }
        }); 
    }

Judging from the errors that I was getting when I ran the code I am guessing that there is a problem with your AJAX because I got a odd POST error when I ran the code and I also discovered that there is a missing ")" but I am not familiar with AJAX so I am just guessing,

SyntaxError: missing ) after argument list

I hope this helps, Conor.

cwalsh
  • 39
  • 4