Getting info from the shadowbox

2 Messages Forum Options Options
Permalink
Dudeeeeeeee
Getting info from the shadowbox
Reply Threaded More
Print post
Permalink
Hello,

I have a problem:
I use shadowbox to show some fields.
When the submit the info and press the button, I want to show that info on the page where the came from (so the page under the shadowbox). How can I read this info?

I tried via Javascript:
document.forms['bla'].subject.value  += document.form.otherbla.value;
And some other codes but nothing seem to work.

I hope you guys can help me!

If you don't understand my problem, please say so, I'm not England.
Wizzud
Re: Getting info from the shadowbox
Reply Threaded More
Print post
Permalink
I would suggest that you might find it easier to use a library, such as jQuery.

Intercept the submit event on the copied form and ...
1. find the original form - how you find it depends on your HTML
2. find the copied form - it's within the context of #shadowbox_content; exactly how you find it depends on your HTML
3. for each input field - INPUT, SELECT, TEXTAREA - in the copied form, set the corresponding field in the original form
4. close Shadowbox
5. return false (presumably you don't want to actually submit the form!)

Example, using jQuery:

<script type='text/javascript'>
//NB this is an untested, single-form, one-way copy!
function copyBacktoOriginal(){ //context (this) is the submitted copy
  var o = $('#someDiv form'); //original form
  // for each field on the copy (that does not have the class 'ignoreField'), set the corresponding field on the original...
  $(':input:not(.ignoreField)', this).each(function(){
    var v = $(this).val() //value of the copy field
       , ch = ({radio:1, checkbox:1}[this.type]) //is radio or checkbox
         //find target field in original form...
       , tgt = this.type=='radio' ? $(':radio[name='+this.name+']', o).filter("[value='"+v+"']") : $(':input[name='+this.name+']', o)
       ;
    // set checked property or value depending on type of field...
    if(tgt.length){
      if(ch) tgt[0].checked = this.checked;
      else tgt.val(v);
    }
  });
  Shadowbox.close();
  return false;
}
$(document).ready(function(){
  var opts = { onFinish : function(){ $('#shadowbox_content form').bind('submit', copyBackToOriginal); } };
  Shadowbox.init(opts);
});
</script>


<div id='someDiv'>
  ....
  <form ...>  ....  </form>
  ....
</div>