aRo` automating your e-commerce

This blog has been neglected due to the success of Solidshops.com
22Jan/08

how to create a popup that returns data to the parent page

In this code snippet i will show you how you can click a button after an input field wich creates a popup. This popup is actually a plain html page where you can enter data into a textarea. When the user is done editing text in the textarea, he can hit the save button and the value from the textarea is saved to the textfield on the main.html page.

main.html

HTML:
  1. <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
  2. <title>Nieuwe pagina 1</title>
  3.     <script type="text/javascript">
  4.         function createpopup(){
  5.             var wind1=null;
  6.             var tmp=null;
  7.             wind1 = window.open('popup.html', 'displayWindow', 'width=400,height=300,status=no,toolbar=no,menubar =no,scrollbars=1');
  8.         }
  9.         function getValues(){
  10.             document.forms["frmform"].elements["txtmail"].value = tmp;
  11.         }
  12.     </script>
  13. </head>
  14.  
  15. <form action="#" name="frmform" method="get">
  16. <input type="text"  name="txtmail" value="" /><button onclick='createpopup();' name ="cmdpopup"/>
  17. </form>
  18. </body>
  19.  
  20. </html>

When the user clicks ont the save button, the data in the textarea is send to a function on the main page that puts the data into the textfield
popup.html

HTML:
  1.     function filltextfield(f){
  2.         var text=f.txttext.value;
  3.         window.opener.tmp=text;
  4.         window.opener.getValues();
  5.         window.close();
  6.         }
  7. </script>
  8. </head>
  9. <form action='#' name='myform' action='post'>
  10. <TEXTAREA rows='2' cols='20' name='txttext'></TEXTAREA><br>
  11. <INPUT type='button' value='save' onclick='javascript:filltextfield(this.form);'>
  12. <INPUT type='button' value='cancel' onclick='javascript:window.close();'>
  13. </form>
  14. </body>
  15. </html>

Popularity: 3% [?]

Filed under: javascript No Comments
14Sep/07

automatically resize iframe height depending on content

You can use this javascript function to resize the height of your iframe depending on the size of your parent page.

JAVASCRIPT:
  1. <script language="JavaScript">
  2. function iFrameHeight() {
  3. if(document.getElementById &amp;&amp; !(document.all)) {
  4. h = document.getElementById('main').contentDocument.body.scrollHeight;
  5. document.getElementById('main').style.height = h + 100;
  6. }
  7. else if(document.all) {
  8. h = document.frames('main').document.body.scrollHeight;
  9. document.all.main.style.height = h + 100;
  10. }
  11. }
  12. </script>

Popularity: 35% [?]

Filed under: javascript 12 Comments
5Mar/06

Setting a maxlenght to a textarea using javascript

If you want to limit the number of characters people can type in a textarea object. U should use a javascript because there is no such "maxlength" attribite as with a "normal" textbox.In the code below i use a small textbox (txtCounter) near the textarea to show the remaining characters.

Paste this code in the tag of your textarea

onkeydown="EditCounter(frmYourForm,500)" onkeyup="EditCounter(frmYourForm,500)"

this is the javascript function

function EditCounter(myform, MaxChar){
var elements = document.getElementsByTagName('textarea');
if (elements[0].value.length >= MaxChar){
elements[0].value = String(elements[0].value).substring(0,MaxChar)
myform.txtCounter.value =MaxChar - elements[0].value.length ;
}else{
myform.txtCounter.value = MaxChar - elements[0].value.length ;
}
}

textcounter

Popularity: 2% [?]

Filed under: javascript No Comments
22Feb/06

Calling a Vbscript msgbox using Javascript

Javascript just offers a simple alert box without any customisation. With the code below u can call a VBscript function from javascript witch makes it possible to create your own alert box with or without an icon.
Javascript function

NS4 = (document.layers);
IE4 = (document.all);
ver4 = (NS4 || IE4);

function newAlert(title,mess,icon,mods) {
(IE4) ? makeMsgBox(title,mess,icon,0,0,mods) : alert(mess);
}

VBScript function

Function makeMsgBox(tit,mess,icons,buts,defs,mods)
butVal = buts + (icons*16) + (defs*256) + (mods*4096)
makeMsgBox = MsgBox(mess,butVal,tit)
End Function

Call the new alert box

newAlert("title","msg",0,0);

Popularity: 2% [?]

Filed under: javascript 1 Comment