0

I've got a command.cgi that returns a website url, if the checkbox with id="simple" is checked then redirect the user to that page, if not, add the html formatted link to a container. The problem is that it doesn't redirect the user to a html formatted link when the checkbox is checked and when it does, it redirects the user to a formatted html link, it's crazy. Any solution? Thanks

<script type="text/javascript">
 $(document).ready(function() {
      $("#sudo").click(function(event){
          if ($("#simple").attr('checked')==1){
                    $.get("/cgi-bin/command.cgi",
                     { cmd: $("#cmd").val()},
                     function(data) {
        window.location.href=data;
                     });
                }else{
                    $.get("/cgi-bin/command.cgi",
                     { cmd: $("#cmd").val()},
                     function(data) {
                        $('#resultado p').prepend("<a href=\"" + data + "\" target=\"_blank\">" + data + "</a><br><br>");
                        $("#cmd").val('');
                        $("#cmd").focus();
                     });  
                }


      });
      $("#cmd").keyup(function(e){
        if(e.keyCode == 13){
            $("#sudo").click();
        }
    });
   });
</script>

1 Answer 1

1

Try:


$("#sudo").click(function(event){
    $.get("/cgi-bin/command.cgi",
     { cmd: $("#cmd").val()},
     function(data) {
        if($("#simple").is(":checked")) {
            window.location.href=data;
        }
        else {
            $('#resultado p').prepend("<a href=\"" + data + "\" target=\"_blank\">" + data + "</a><br><br>");
            $("#cmd").val('');
            $("#cmd").focus();
        }
     });
});

Sign up to request clarification or add additional context in comments.

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.