Skip to main content

$("#form”).attr("method”, "post”) is In java Script ASP.NET



I have a Grid view where I have a hyper link button which displays ID, by clicking on it I make a Ajax call to the server and get the specific URL to navigate against of the ID. After the Ajax call complete I call the following Codes to open the respective page in New Tab/Window.







function RedirectPageUrl(rqstID) {

$("#formMain").attr("action", rqstID);

$("#formMain").attr("method", "post");

$("#formMain").attr('target', '_blank');

$("#formMain").submit();

return false;

}







Here my problem is after clicking on the First hyperlink button things are working perfectly but then onwards whenever I click on any control (say Button)the previous opened form opens up. How to get rid of it any idea??


Comments

  1. Because you have modified the action and other attributes of the main form on your page which I guess is the same #formMain'. So next time whenever you try to click on any button which postbacks to the server it submits the form to the action set by previousRedirectPageUrl` method call.

    You can try something like this which is basically using a different form for redirecting to another page. This way the main form remains unchanged and other functionalities on the page are not affected.

    function RedirectPageUrl(rqstID) {
    var $redirectForm = $('#redirectForm');
    if($redirectForm.length == 0){
    $redirectForm = $('<form id="redirectForm" method="post" target="_blank" />')
    .appendTo(document.body);
    }
    $redirectForm
    .attr("action", rqstID)
    .submit();
    return false;
    }

    ReplyDelete

Post a Comment

Popular posts from this blog

Why is this Javascript much *slower* than its jQuery equivalent?

I have a HTML list of about 500 items and a "filter" box above it. I started by using jQuery to filter the list when I typed a letter (timing code added later): $('#filter').keyup( function() { var jqStart = (new Date).getTime(); var search = $(this).val().toLowerCase(); var $list = $('ul.ablist > li'); $list.each( function() { if ( $(this).text().toLowerCase().indexOf(search) === -1 ) $(this).hide(); else $(this).show(); } ); console.log('Time: ' + ((new Date).getTime() - jqStart)); } ); However, there was a couple of seconds delay after typing each letter (particularly the first letter). So I thought it may be slightly quicker if I used plain Javascript (I read recently that jQuery's each function is particularly slow). Here's my JS equivalent: document.getElementById('filter').addEventListener( 'keyup', function () { var jsStart = (new Date).getTime()...

Is it possible to have IF statement in an Echo statement in PHP

Thanks in advance. I did look at the other questions/answers that were similar and didn't find exactly what I was looking for. I'm trying to do this, am I on the right path? echo " <div id='tabs-".$match."'> <textarea id='".$match."' name='".$match."'>". if ($COLUMN_NAME === $match) { echo $FIELD_WITH_COLUMN_NAME; } else { } ."</textarea> <script type='text/javascript'> CKEDITOR.replace( '".$match."' ); </script> </div>"; I am getting the following error message in the browser: Parse error: syntax error, unexpected T_IF Please let me know if this is the right way to go about nesting an IF statement inside an echo. Thank you.