2

I have a form with a textarea and a button. To show the textarea value in another tab of the same window on a button click I used this:

<input type="button" name="preview" id="inline_submit_a" value="PREVIEW" />
<script>
    $('#inline_submit_a').click(function(evt) {
        var msg = document.getElementById('message').value;
        var myLineBreak = msg.replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '<br />');

        jQuery.ajax({
            type: 'POST',
            url: '/someajax.php',
            data: "msg="+myLineBreak,
            success: function(data) {
                window.open("<?=SITEURL?>includes/templates/preview/template1/postoffer_preview.php?offer="+data,'_blank');
                return false;
            }
        });
    });
</script>

I'm sending through query string,

  1. How to send the value to another page through POST and not the query string(GET) since it takes only upto limited characters.

  2. Also, How to get the html content (With breaks), I used this: var myLineBreak = msg.replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '<br />'); But breaks for some text.

  3. Also, window.open("<?=SITEURL?>test.php?msg="+data,'_blank'); this works good in firefox, but in Chrome, it opens a new window,

Can someone pls help me on this.. am I going in the right direction?

Thanks

1
  • instead of opening a new window why not use something like a lightbox?
    – Rooster
    Apr 27, 2012 at 13:18

1 Answer 1

0

Something like this, using form.target and empty window.open (code not tested) :

<form name="myform" action="postoffer_preview.php" target="myNewWin" method=post"> 
   <input type="button" name="preview" id="inline_submit_a" value="PREVIEW" />
</form> 

<script>
    var open_post_window = function () 
    { 
        window.open("","myNewWin","width=500,height=300,toolbar=0"); 
        document.myform.submit(); 
    } 

    $('#inline_submit_a').click(function(evt) {
        var msg = document.getElementById('message').value;
        var myLineBreak = msg.replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '<br />');

        jQuery.ajax({
            type: 'POST',
            url: '/someajax.php',
            data: "msg="+myLineBreak,
            success: function(data) {
                open_post_window();
                return false;
            }
        });
    });
</script>

Add a little setTimeout on document.myform.submit() may be necessary.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.