JavaScript - Javascript Good Parts "the Method Invocation Pattern" Why Not Work
This is my first post.
I am reading "Javascript The Good Parts" ~ The Method Invocation Pattern Page 28 and tried this, var myObject= { value:0, increment:function(inc){ this.value+= typeof inc==="number" ? inc:1; } } myObject.increment(2); alert(myObject.value); but alert(myObject.value); is returning a value of "2", when it should return "3". Can someone help? Reply With Quote 12-22-2014, 09:59 AM #2 rnd me View Profile View Forum Posts Visit Homepage Senior Coder Join Date Jun 2007 Location Urbana Posts 4,497 Thanks 11 Thanked 603 Times in 583 Posts 0+2=2, not 3; the code is working correctly. Similar TutorialsHi guys, I have a JS calculator on my website which is basically a load of radio buttons that the user clicks and as they do so a price is calculated in their view. At the moment - the price box starts with a blank box but is essentially "0". Then, as the user select an option, the price appears and then starts to calculate when more than 1 is pressed. All I want to do is have the price start at "300" instead of a blank box or "0". Then the rest of the options calculate onto that. I have tried a variety of ways to achieve it and seem to be missing something! I am pretty new to JS although do have a basic understanding ..... clearly not enough to do this thou! lol Basically imagine 300 is the initial price. That only gets charged once ... Here's my code .... In the <head> Code: <script type="text/javascript"> function getRBtnName(GrpName) { var sel = document.getElementsByName(GrpName); var fnd = -1; var str = ''; for (var i=0; i<sel.length; i++) { if (sel[i].checked == true) { str = sel[i].value; fnd = i; } } return fnd; // return option index of selection // comment out next line if option index used in line above // return str; } function chkrads(rbGroupName) { var ExPg = [ [0,''], [100,"1 extra page"], [200,"2 extra pages"], [250,"3 extra pages"], [300,"4 extra pages"], [350,"5 extra pages"] ]; var ExEm = [ [0,''], [10,"1 extra email"], [20,"2 extra emails"], [30,"3 extra emails"], [40,"4 extra emails"], [50,"5 extra emails"] ]; var ImgBun = [ [0,''], [10,"3 extra image"], [20,"5 extra images"], [30,"7 extra images"], [40,"10 extra images"] ]; var rbtnGroupNames = ['extrapages','extraemail','imagebundles']; var totalprice = 0; var tmp = ''; var items = []; for (var i=0; i<rbtnGroupNames.length; i++) { tmp = getRBtnName(rbtnGroupNames[i]); if (tmp != -1) { switch (i) { case 0 : totalprice += ExPg[tmp][0]; if (tmp > 0) { items.push(ExPg[tmp][1]); } break; case 1 : totalprice += ExEm[tmp][0]; if (tmp > 0) { items.push(ExEm[tmp][1]); } break; case 2 : totalprice += ImgBun[tmp][0]; if (tmp > 0) { items.push(ImgBun[tmp][1]); } break; } } } document.getElementById('QUOTED_PRICE').value = totalprice; document.getElementById('ITEMS_SELECTED').value = items.join('\n'); document.getElementById('PRICE_IN_VIEW').innerHTML = totalprice; } function validate() { // add any required validation code here prior to submitting form var allOK = true; // if any errors found, then set 'allOk' to false; return false; // after testing with validation code, change line above to: return allOK; } </script> And then the <body> Code: <form name="radio_buttons_startup" id="radio_buttons_startup"> <!--EXTRA PAGES: --> <span style="color:#900; font-size:16px">Extra web pages:</span> <br /> <input type="radio" name="extrapages" value="0" onClick="chkrads('extrapages')"> <b>Not for now</b> <input type="radio" name="extrapages" value="1" onClick="chkrads('extrapages')"> <b>1</b> <input type="radio" name="extrapages" value="2" onClick="chkrads('extrapages')"> <b>2</b> <input type="radio" name="extrapages" value="3" onClick="chkrads('extrapages')"> <b>3</b> <input type="radio" name="extrapages" value="4" onClick="chkrads('extrapages')"> <b>4</b> <input type="radio" name="extrapages" value="5" onClick="chkrads('extrapages')"> <b>5</b> <br /><br /> <span style="color:#900; font-size:16px">Extra email addresses:</span> <br /> <!-- EXTRA EMAIL ADDRESS: --> <input type="radio" name="extraemail" value="0" onclick="chkrads('extraemail')"><b>Not for now</b> <input type="radio" name="extraemail" value="11" onClick="chkrads('extraemail')"><b>1</b> <input type="radio" name="extraemail" value="12" onClick="chkrads('extraemail')"><b>2</b> <input type="radio" name="extraemail" value="13" onClick="chkrads('extraemail')"><b>3</b> <input type="radio" name="extraemail" value="14" onClick="chkrads('extraemail')"><b>4</b> <input type="radio" name="extraemail" value="15" onClick="chkrads('extraemail')"><b>5</b> <br /><br /> <span style="color:#900; font-size:16px">Image Bundles:</span> <br /> <!--Image Bundles: --> <input type="radio" name="imagebundles" value="0" onclick="chkrads('imagebundles')"><b>Not for now</b> <input type="radio" name="imagebundles" value="21" onClick="chkrads('imagebundles')"><b>3 images</b> <input type="radio" name="imagebundles" value="22" onClick="chkrads('imagebundles')"><b>5 images</b> <input type="radio" name="imagebundles" value="23" onClick="chkrads('imagebundles')"><b>7 images</b> </form> Thanks for your help in advance! I am running on Magento eCommerce, however please don't turn away if you have no experience with it. Problem is with JavaScript. When one clicks on the button, nothing happens, when the page loads browsers in general display error message, that 'productAddtoCartForm' is null or not an object Here's the piece of code around the Add button: Code: <div class="product-view"> <div class="product-essential"> <form action="http://myhairpalace.com/index.php/default/checkout/cart/add/uenc/aHR0cDovL215aGFpcnBhbGFjZS5jb20vaW5kZXgucGhwL2RlZmF1bHQvaW5kaWFuLXJlbXktZnJvbnQvMTAwLWh1bWFuLWhhaXItbGFjZS1mcm9udC13aWctc3V6aWUuaHRtbD9fX19TSUQ9VQ,,/product/57/" method="post" id="product_addtocart_form" enctype="multipart/form-data"> <div class="no-display"> <input type="hidden" name="product" value="57� /> <input type=" hidden"="" id="related-products-field" product-shop"=""> <div class="product-name"> <h1>100% Human Hair Lace Front Wig-Suzie</h1> </div> <p class="email-friend"><a href="http://myhairpalace.com/index.php/default/sendfriend/product/send/id/57/cat_id/11/">Email to a Friend</a></p> <p class="no-rating"><a href="http://myhairpalace.com/index.php/default/review/product/list/id/57/category/11/#review-form">Be the first to review this product</a></p> <p class="availability in-stock">Availability: <span>In stock</span></p> <div class="price-box"> <span class="regular-price" id="product-price-57"> <span class="price">$75.00</span> </span> </div> <ul class="add-to-links"> <li><a href="http://myhairpalace.com/index.php/default/wishlist/index/add/product/57/" class="link-wishlist">Add to Wishlist</a></li> <li><span class="separator">|</span> <a href="http://myhairpalace.com/index.php/default/catalog/product_compare/add/product/57/uenc/aHR0cDovL215aGFpcnBhbGFjZS5jb20vaW5kZXgucGhwL2RlZmF1bHQvaW5kaWFuLXJlbXktZnJvbnQvMTAwLWh1bWFuLWhhaXItbGFjZS1mcm9udC13aWctc3V6aWUuaHRtbD9fX19TSUQ9VQ,,/" class="link-compare">Add to Compare</a></li> </ul> <div class="short-description"> <h2>Quick Overview</h2> <div class="std">Suzie</div> </div> </div> <div class="product-img-box"> <p class="product-image product-image-zoom"> <img id="image" src="http://myhairpalace.com/media/catalog/product/cache/1/image/9df78eab33525d08d6e5fb8d27136e95/l/a/lace_front-shan.jpg" alt="100% Human Hair Lace Front Wig-Suzie" title="100% Human Hair Lace Front Wig-Suzie"></p> <p class="zoom-notice" id="track_hint">Double click on above image to view full picture</p> <div class="zoom"> <img id="zoom_out" src="http://myhairpalace.com/skin/frontend/default/default/images/slider_btn_zoom_out.gif" alt="Zoom Out" title="Zoom Out" class="btn-zoom-out"> <div id="track"> <div id="handle"></div> </div> <img id="zoom_in" src="http://myhairpalace.com/skin/frontend/default/default/images/slider_btn_zoom_in.gif" alt="Zoom In" title="Zoom In" class="btn-zoom-in"> </div> <script type="text/javascript"> //<![CDATA[ Event.observe(window, 'load', function() { product_zoom = new Product.Zoom('image', 'track', 'handle', 'zoom_in', 'zoom_out', 'track_hint'); }); //]]> </script> <div class="more-views"> <h2>More Views</h2> <ul> <li> <a href="#" onclick="popWin('http://myhairpalace.com/index.php/default/catalog/product/gallery/id/57/image/56/', 'gallery', 'width=300,height=300,left=0,top=0,location=no,status=yes,scrollbars=yes,resizable=yes'); return false;" title=""><img src="http://myhairpalace.com/media/catalog/product/cache/1/thumbnail/56x/9df78eab33525d08d6e5fb8d27136e95/l/a/lace_front-shan.jpg" width="56" height="56" alt=""></a> </li> </ul> </div> </div> <div class="clearer"></div> <div class="product-options" id="product-options-wrapper"> <script type="text/javascript"> //<![CDATA[ var DateOption = Class.create({ getDaysInMonth: function(month, year) { var curDate = new Date(); if (!month) { month = curDate.getMonth(); } if (2 == month && !year) { // leap year assumption for unknown year return 29; } if (!year) { year = curDate.getFullYear(); } return 32 - new Date(year, month - 1, 32).getDate(); }, reloadMonth: function(event) { var selectEl = event.findElement(); var idParts = selectEl.id.split("_"); if (idParts.length != 3) { return false; } var optionIdPrefix = idParts[0] + "_" + idParts[1]; var month = parseInt($(optionIdPrefix + "_month").value); var year = parseInt($(optionIdPrefix + "_year").value); var dayEl = $(optionIdPrefix + "_day"); var days = this.getDaysInMonth(month, year); //remove days for (var i = dayEl.options.length - 1; i >= 0; i--) { if (dayEl.options[i].value > days) { dayEl.remove(dayEl.options[i].index); } } // add days var lastDay = parseInt(dayEl.options[dayEl.options.length-1].value); for (i = lastDay + 1; i <= days; i++) { this.addOption(dayEl, i, i); } }, addOption: function(select, text, value) { var option = document.createElement('OPTION'); option.value = value; option.text = text; if (select.options.add) { select.options.add(option); } else { select.appendChild(option); } } }); var dateOption = new DateOption(); //]]> </script> <script type="text/javascript"> //<![CDATA[ var optionFileUpload = { productForm : $('product_addtocart_form'), formAction : '', formElements : {}, upload : function(element){ this.formElements = this.productForm.select('input', 'select', 'textarea', 'button'); this.removeRequire(element.readAttribute('id').sub('option_', '')); template = '<iframe id="upload_target" name="upload_target" style="width:0; height:0; border:0;"><\/iframe>'; Element.insert($('option_'+element.readAttribute('id').sub('option_', '')+'_uploaded_file'), {after: template}); this.formAction = this.productForm.action; var baseUrl = 'http://myhairpalace.com/index.php/default/catalog/product/upload/'; var urlExt = 'option_id/'+element.readAttribute('id').sub('option_', ''); this.productForm.action = parseSidUrl(baseUrl, urlExt); this.productForm.target = 'upload_target'; this.productForm.submit(); this.productForm.target = ''; this.productForm.action = this.formAction; }, removeRequire : function(skipElementId){ for(var i=0; i<this.formElements.length; i++){ if (this.formElements[i].readAttribute('id') != 'option_'+skipElementId+'_file' && this.formElements[i].type != 'button') { this.formElements[i].disabled='disabled'; } } }, addRequire : function(skipElementId){ for(var i=0; i<this.formElements.length; i++){ if (this.formElements[i].readAttribute('name') != 'options_'+skipElementId+'_file' && this.formElements[i].type != 'button') { this.formElements[i].disabled=''; } } }, uploadCallback : function(data){ this.addRequire(data.optionId); $('upload_target').remove(); if (data.error) { } else { $('option_'+data.optionId+'_uploaded_file').value = data.fileName; $('option_'+data.optionId+'_file').value = ''; $('option_'+data.optionId+'_file').hide(); $('option_'+data.optionId+'').hide(); template = '<div id="option_'+data.optionId+'_file_box"><a href="#"><img src="var/options/'+data.fileName+'" alt=""><\/a><a href="#" onclick="optionFileUpload.removeFile('+data.optionId+')" title="Remove file" \/>Remove file<\/a>'; Element.insert($('option_'+data.optionId+'_uploaded_file'), {after: template}); } }, removeFile : function(optionId) { $('option_'+optionId+'_uploaded_file').value= ''; $('option_'+optionId+'_file').show(); $('option_'+optionId+'').show(); $('option_'+optionId+'_file_box').remove(); } } var optionTextCounter = { count : function(field,cntfield,maxlimit){ if (field.value.length > maxlimit){ field.value = field.value.substring(0, maxlimit); } else { cntfield.innerHTML = maxlimit - field.value.length; } } } Product.Options = Class.create(); Product.Options.prototype = { initialize : function(config){ this.config = config; this.reloadPrice(); }, reloadPrice : function(){ price = new Number(); config = this.config; skipIds = []; $$('.product-custom-option').each(function(element){ var optionId = 0; element.name.sub(/[0-9]+/, function(match){ optionId = match[0]; }); if (this.config[optionId]) { if (element.type == 'checkbox' || element.type == 'radio') { if (element.checked) { if (config[optionId][element.getValue()]) { price += parseFloat(config[optionId][element.getValue()]); } } } else if(element.hasClassName('datetime-picker') && !skipIds.include(optionId)) { dateSelected = true; $$('.product-custom-option[id^="options_' + optionId + '"]').each(function(dt){ if (dt.getValue() == '') { dateSelected = false; } }); if (dateSelected) { price += parseFloat(this.config[optionId]); skipIds[optionId] = optionId; } } else if(element.type == 'select-one' || element.type == 'select-multiple') { if (element.options) { $A(element.options).each(function(selectOption){ if (selectOption.selected) { if (this.config[optionId][selectOption.value]) { price += parseFloat(this.config[optionId][selectOption.value]); } } }); } } else { if (element.getValue().strip() != '') { price += parseFloat(this.config[optionId]); } } } }); try { optionsPrice.changePrice('options', price); optionsPrice.reload(); } catch (e) { } } } function validateOptionsCallback(elmId, result){ var container = $(elmId).up('ul.options-list'); if (result == 'failed') { container.removeClassName('validation-passed'); container.addClassName('validation-failed'); } else { container.removeClassName('validation-failed'); container.addClassName('validation-passed'); } } var opConfig = new Product.Options({"80":{"447":0,"448":0,"451":0,"452":0,"449":0,"450":0,"454":0,"453":0}}); //]]> </script> <dl> <dt><label>Color<span class="required"> *</span></label></dt> <dd class="last"> <select name="options[80]" id="select_80" class=" required-entry product-custom-option" title="" onchange="opConfig.reloadPrice()"><option value="">-- Please Select --</option><option value="447">1 </option><option value="448">1B </option><option value="451">1B/30 </option><option value="452">1B/33 </option><option value="449">2 </option><option value="450">4 </option><option value="454">4/27 </option><option value="453">4/30 </option></select> </dd> </dl> <script type="text/javascript"> //<![CDATA[ enUS = {"m":{"wide":["January","February","March","April","May","June","July","August","September","October","November","December"],"abbr":["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]}}; // en_US locale reference Calendar._DN = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]; // full day names Calendar._SDN = ["Sun","Mon","Tue","Wed","Thu","Fri","Sat"]; // short day names Calendar._FD = 0; // First day of the week. "0" means display Sunday first, "1" means display Monday first, etc. Calendar._MN = ["January","February","March","April","May","June","July","August","September","October","November","December"]; // full month names Calendar._SMN = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]; // short month names Calendar._am = "AM"; // am/pm Calendar._pm = "PM"; // tooltips Calendar._TT = {}; Calendar._TT["INFO"] = "About the calendar"; Calendar._TT["ABOUT"] = "DHTML Date/Time Selector\n" + "(c) dynarch.com 2002-2005 / Author: Mihai Bazon\n" + "For latest version visit: http://www.dynarch.com/projects/calendar/\n" + "Distributed under GNU LGPL. See http://gnu.org/licenses/lgpl.html for details." + "\n\n" + "Date selection:\n" + "- Use the \xab, \xbb buttons to select year\n" + "- Use the " + String.fromCharCode(0x2039) + ", " + String.fromCharCode(0x203a) + " buttons to select month\n" + "- Hold mouse button on any of the above buttons for faster selection."; Calendar._TT["ABOUT_TIME"] = "\n\n" + "Time selection:\n" + "- Click on any of the time parts to increase it\n" + "- or Shift-click to decrease it\n" + "- or click and drag for faster selection."; Calendar._TT["PREV_YEAR"] = "Prev. year (hold for menu)"; Calendar._TT["PREV_MONTH"] = "Prev. month (hold for menu)"; Calendar._TT["GO_TODAY"] = "Go Today"; Calendar._TT["NEXT_MONTH"] = "Next month (hold for menu)"; Calendar._TT["NEXT_YEAR"] = "Next year (hold for menu)"; Calendar._TT["SEL_DATE"] = "Select date"; Calendar._TT["DRAG_TO_MOVE"] = "Drag to move"; Calendar._TT["PART_TODAY"] = ' (' + "Today" + ')'; // the following is to inform that "%s" is to be the first day of week Calendar._TT["DAY_FIRST"] = "Display %s first"; // This may be locale-dependent. It specifies the week-end days, as an array // of comma-separated numbers. The numbers are from 0 to 6: 0 means Sunday, 1 // means Monday, etc. Calendar._TT["WEEKEND"] = "0,6"; Calendar._TT["CLOSE"] = "Close"; Calendar._TT["TODAY"] = "Today"; Calendar._TT["TIME_PART"] = "(Shift-)Click or drag to change value"; // date formats Calendar._TT["DEF_DATE_FORMAT"] = "%b %e, %Y"; Calendar._TT["TT_DATE_FORMAT"] = "%B %e, %Y"; Calendar._TT["WK"] = "Week"; Calendar._TT["TIME"] = "Time:"; //]]> </script> <p class="required">* Required Fields</p> </div> <script type="text/javascript">decorateGeneric($$('#product-options-wrapper dl'), ['last']);</script> <div class="product-options-bottom"> <div class="price-box"> <span class="regular-price" id="product-price-57_clone"> <span class="price">$75.00</span> </span> </div> <div class="add-to-cart"> <label for="qty">Qty:</label> <input type="text" name="qty" id="qty" maxlength="12" value="1" title="Qty" class="input-text qty"> <button type="button" title="Add to Cart" class="button btn-cart" onclick="productAddToCartForm.submit()"><span><span>Add to Cart</span></span></button> <p class="paypal-logo"><a id="ec_shortcut_c2e3fb1be4b9e9d53800cbc4d5f1e274" href="http://myhairpalace.com/index.php/default/paypal/express/start/"> <img src="https://fpdbs.paypal.com/dynamicimageweb?cmd=_dynamic-image&buttontype=ecshortcut&locale=en_US" alt="Checkout with PayPal"> </a> <input type="hidden" id="pp_checkout_url" name="return_url" value=""> <script type="text/javascript"> //<![CDATA[ Event.observe('ec_shortcut_c2e3fb1be4b9e9d53800cbc4d5f1e274', 'click', function(event) { $('pp_checkout_url').value = this.href; productAddToCartForm.submit(); event.stop(); }); //]]> </script></p> </div> </div> </form> <script type="text/javascript"> //<![CDATA[ var productAddToCartForm = new VarienForm('product_addtocart_form'); productAddToCartForm.submit = function(){ if (this.validator.validate()) { this.form.submit(); } }.bind(productAddToCartForm); //]]> </script> </div> <div class="product-collateral"> <div class="box-collateral box-description"> <h2>Details</h2> <div class="std"> Nautral Hairline 100% Human Hair Lace Front wig. </div> </div> <div class="box-collateral box-tags"> <h2>Product Tags</h2> <form id="addTagForm" action="http://myhairpalace.com/index.php/default/tag/index/save/product/57/uenc/aHR0cDovL215aGFpcnBhbGFjZS5jb20vaW5kZXgucGhwL2RlZmF1bHQvaW5kaWFuLXJlbXktZnJvbnQvMTAwLWh1bWFuLWhhaXItbGFjZS1mcm9udC13aWctc3V6aWUuaHRtbD9fX19TSUQ9VQ,,/" method="get"> <div class="form-add"> <label for="productTagName">Add Your Tags:</label> <div class="input-box"> <input type="text" class="input-text required-entry" name="productTagName" id="productTagName"> </div> <button type="button" title="Add Tags" class="button" onclick="submitTagForm()"> <span> <span>Add Tags</span> </span> </button> </div> </form> <p class="note">Use spaces to separate tags. Use single quotes (') for phrases.</p> <script type="text/javascript"> //<![CDATA[ var addTagFormJs = new VarienForm('addTagForm'); function submitTagForm(){ if(addTagFormJs.validator.validate()) { addTagFormJs.form.submit(); } } //]]> </script> </div> </div> </div> Magento uses Prototype framework and the problem has something to do with prototype.js file and indeed, when I debugged in Chrome, here's what came up: Now, the crux is that the error shows up only pages featuring products w/ options in dropdown menus: http://myhairpalace.com/index.php/de...inkerbell.html You are able to add Simple Products to cart just fine: http://myhairpalace.com/index.php/de...o-measure.html I would be incredibly grateful for ANY suggestions. Code: for(i=0;i<document.getElementsByName('checkresult_".$i."').length;++i){ if(document.getElementsByName('checkresult_".$i."')[i].checked){ thisurlext+=document.getElementsByName('checkresult_".$i."')[i].value; checkedlength++; if(i+1<document.getElementsByName('checkresult_".$i."').length){ if(document.getElementsByName('checkresult_".$i."')[i+1].checked){ thisurlext+='+'; } } } }; Let's say I check verses 1, 2, 3, 6 I want the Javascript not to ignore the + between the 3 and the 6: Code: <div id="txt_kjv0_1_1_0" style="float: left; background-color: rgb(234, 232, 200); margin: 0px; width: 178px; height: 497px; border: 1px solid rgb(122, 16, 16); padding: 5px 5px 0px; overflow-y: auto; overflow-x: hidden;"> <input id="sc0" value="kjv" type="hidden"> <p id="regular[]" name="bibletext" style="float: left; text-align: left; width: 155px; display: block; padding: 0px 2px; font-size: 12px;"><input id="check0_0" name="checkresult_0" onclick="" value="1" type="checkbox"><span style="font-weight: bold; margin: 2px;">1</span>In the beginning God created the heaven and the earth.</p> <p id="regular[]" name="bibletext" style="float: left; text-align: left; width: 155px; display: block; padding: 0px 2px; font-size: 12px;"><input id="check0_1" name="checkresult_0" onclick="" value="2" type="checkbox"><span style="font-weight: bold; margin: 2px;">2</span>And the earth was without form, and void; and darkness was upon the face of the deep. And the Spirit of God moved upon the face of the waters.</p> <p id="regular[]" name="bibletext" style="float: left; text-align: left; width: 155px; display: block; padding: 0px 2px; font-size: 12px;"><input id="check0_2" name="checkresult_0" onclick="" value="3" type="checkbox"><span style="font-weight: bold; margin: 2px;">3</span>And God said, Let there be light: and there was light.</p> <p id="regular[]" name="bibletext" style="float: left; text-align: left; width: 155px; display: block; padding: 0px 2px; font-size: 12px;"><input id="check0_3" name="checkresult_0" onclick="" value="4" type="checkbox"><span style="font-weight: bold; margin: 2px;">4</span>And God saw the light, that it was good: and God divided the light from the darkness.</p> <p id="regular[]" name="bibletext" style="float: left; text-align: left; width: 155px; display: block; padding: 0px 2px; font-size: 12px;"><input id="check0_4" name="checkresult_0" onclick="" value="5" type="checkbox"><span style="font-weight: bold; margin: 2px;">5</span>And God called the light Day, and the darkness he called Night. And the evening and the morning were the first day.</p> <p id="regular[]" name="bibletext" style="float: left; text-align: left; width: 155px; display: block; padding: 0px 2px; font-size: 12px;"><input id="check0_5" name="checkresult_0" onclick="" value="6" type="checkbox"><span style="font-weight: bold; margin: 2px;">6</span>And God said, Let there be a firmament in the midst of the waters, and let it divide the waters from the waters.</p> Can someone help me to edit this code...? I already tried to modify the script in many ways, but it doesn't work, I deleted the lines from the password in the script and also deleted the html to fill the password and do not work.. I dont really know wht to do.. I search online for a script, but i only find "user name and password" scripts, I just want a unlimited user name with no passwords... I dont need any type of security in the page, that is why I choose this script, but I dont need the password login.. .. This script is easy for me because it has HTML , I know there are other script on php, but are to complicated for me... I know this is very easy, but I dont know Java script, Im learning now.. NOTE: this page has "User name" and "password" to login or redirect to another page.. But I dont need the password option.. I just need the " user name"... I just want he visitor to Enter his/her "user name" and press login and the website will take him/her to a specific page for this user.. I want to have unlimited "user names" with NO passwords.... Can SOMEONE HELP ME WITH THIS... ====================== Here is the code to edit: =============================== <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <SCRIPT LANGUAGE="JavaScript"> <!-- The JavaScript Source --> <!-- Begin function Login(){ var done=0; var username=document.login.username.value; username=username.toLowerCase(); var password=document.login.password.value; password=password.toLowerCase(); if (username=="member1" && password=="password1") { window.location="page1.html"; done=1; } if (username=="member2" && password=="password2") { window.location="page2.html"; done=1; } if (username=="member3" && password=="password3") { window.location="page3.html"; done=1; } if (done==0) { alert("Invalid login!"); } } // End --> </SCRIPT> </head> <body> <center> <form name=login> <table width=225 border=0 cellpadding=0> <tr><td colspan=2><center><font size="+2"><b>Members-Only Area!</b></font></center></td></tr> <tr><td>Username:</td><td><input type=text name=username></td></tr> <tr><td>Password:</td><td><input type=text name=password></td></tr> <tr><td colspan=2 align=center><input type=button value="Login!" onClick="Login()"></td></tr> </table> </form> <p> </p> </center> <p> <p> </body> </html> well the jquery is working fine for twitter and other stuff but its not working for facebook, when i highlight the text and select fb to share at then the facebook share just show the meta description of site and not the selected area. I am not able to understand where am i going wrong, any assistance provided is highly appreciated. Go to this link http://www.blobh.com/2011/09/testing-1.html there select some text then a tooltip kind of thing will appear first share at twitter then at facebook you will understand the matter. the script i am using is this Code: <script type='text/javascript'> $('.demo1').selectedTextSharer({ lists:"Twitter,http://twitter.com/home?status=%ts ,favicon|Facebook,http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.blobh.com%2F&t=%s,favicon|Wikipedia (en),http://en.wikipedia.org/w/index.php?title=Special:Search&search=%s,favicon|Google Maps,http://maps.google.com/?q=%s,favicon", extraClass: 'dark', title: 'Share this text ...', borderColor: '#7F241C', background : '#4F663A', titleColor : '#7F241C', textColor : '#FFFFFF', hoverColor: '#7F241C' }); </script> and the other script is this one http://bloghuts.googlecode.com/files...-sharer.min.js and the html is like this Code: <!-- Just wrap a text with a div and add a class, thats all ! --> <div class="demo1"> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it</div> <textarea class="demo4"></textarea> <input class="demo4" type="text" /> Greetings! Let me start by first stating that I've never really coded Javascript before in my life. Having said that, I'm not an idiot and I can generally pick up on things relatively quickly . So, now to the point. I'm currently creating a site in which I've incorporated Protoswitcher (http://cssrevolt.com/upload/files/pr...her/index.html). From what I can tell, it's a relatively simple script. Now the catch is that I wanted to have more than one switcher on my site. And this is where I get stuck. What I did initially was to basically copy the JS file (protoswitcher.js) and rename it something else (userbar.js, for example). I then changed the various places in the script which were previously for "var ProtoSwitcher" to "var UserBar", etc. I managed to get it all to work fine. Both the boxes show up, and they both work as they should (clicking on them changes select bits of CSS). Now the problem I'm having is that the original protoswitcher uses cookies to remember a persons preferences. I cannot for the life of me figure out how to get the "new" protoswitcher (userbar.js) to work with cookies as well. Any help would be much appreciated, and I'm sure I can give you a few dollars for your time . Please let me know if I haven't made sense. TLDL: I want to be able to use several protoswitchers with working cookies. I don't know how. Does anyone have a sizeable popup that will work in google chrome?? I have tried several scripts for this with no success, they all open full page.. Here is an example of what I am looking for... The problem with this is it opens a new page plus a full page popup Code: <script type="text/javascript"> <!-- function popup(url) { var is_chrome; var width = 1020; var height = 600; var left = (screen.width - width)/2; var top = (screen.height - height)/2; var params = 'width='+width+', height='+height; params += ', top='+top+', left='+left; params += ', directories=no'; params += ', location=no'; params += ', menubar=no'; params += ', resizable=yes'; params += ', scrollbars=yes'; params += ', status=no'; params += ', toolbar=no'; newwin=window.open(url,'windowname5', params); is_chrome= navigator.userAgent.toLowerCase().indexOf('chrome') > -1; if (is_chrome) {newwindow.parent.blur();} if (window.focus) {newwin.focus()} return false; } // --> </script> To open I am using Code: onclick=popup(mypage.php?id=".$row->id." Code: <html> <body> var j=0; var temp,temp2,temp3; <script> function scor(j) { switch(j) { case 1: alert("Απαντήσατε σωστά μόνο σε μία ερώτηση.Προσπαθήστε πάλι"); break; case 2: alert("Απαντήσατε σωστά στις δύο από τις τρείς ερωτήσεις"); break; default: alert ("Συγχαρητήρια απαντήσατε σωστά και στις τρεις ερωτήσεις"); } } </script> <meta http-equiv="content-type" content="text/hmtl; charset=iso-8859-7"> <p align="center"><font size="5">Σε μία σελίδα html πόσα είναι τα μέγιστα frames που μπορούμε να τοποθετήσουμε; </p></font> <form name="for1"> <input type="radio" name="fr1"value="1" > 5 <br> <input type="radio" name="fr1"value="2" > Όσα τα pixels<br> <input type="radio" name="fr1"value="3" > Δεν υπάρχει όριο<br> <input type="button" value="Εκχώρηση Απάντησης" onClick="getVal1()"> </form> <script type = "text/javascript"> function getVal1() { for(var i=0; i<document.for1.fr1.length; i++) { if (document.for1.fr1[i].checked) { if (document.for1.fr1[i].value==2) { j++; } } } } function getVal2() { for (var i=0;i<document.for2.fr2.length;i++) { if (document.for2.fr2[i].checked) { if (document.for2.fr2[i].value==2) { j++; } } } } function getVal3() { for (var i=0;i<document.for3.fr3.length;i++) { if (document.for3.fr3[i].checked) { if (document.for3.fr3[i].value==3) { j++; } } } } </script> <p align="center"><font size="5"> Είναι απαραίτητο σε κάθε σελίδα html να υπάρχουν τα tags head και title;</p></font> <form name="for2"> <input type="radio" name="fr2" value="1"> Ναι <br> <input type="radio" name="fr2" value="2"> Όχι <br> <input type="button" value="Εκχώρηση Απάντησης" onClick="getVal2()"> </form> <p align="center"><font size="5"> Τι κάνει το εξής tag: meta http-equiv="content-type" content="text/hmtl; charset=iso-8859-7" </p></font> <form name="for3"> <input type ="radio" name="fr3" value="1"> Δημιουργεί τις προυποθέσεις για την απόκτηση τιμών <br> <input type ="radio" name="fr3" value="2"> Ισσοροπεί τις παραγράφους σε στήλες <br> <input type ="radio" name="fr3" value="3"> Επιτρέπει την κωδικοποίηση ελληνικών χαρακτήρων στην ιστοσελίδα <br> <input type="button" value="Εκχώρηση Απάντησης" onClick="getVal3()" </form> <input type ="button" value="Υπολογισμός" onClick="scor(j)"> Apart from any logical mistakes this thing i have created might have , my question is this.Why upon pressing the last button and calling the "scor(j)" function , no alerts pop up?Thanks in advance. I'm completely stumbled by this as i have no clue as what might be wrong.But then again , my experience is extremely limited so that the form only submits when 2 fields are identical? this is the code I am trying to edit Code: <div class="title">ENROLLMENT</div> <p>You are on your way to receiving <strong>generous cash backs</strong> <em>PLUS</em> a <strong>steady stream of free dinners</strong> just for shopping at your favorite stores!</p> <br /> <form action="" class="registration" id="cform"> <div> To begin, please complete the following:<br /> <div class="f11"> <input type="text" name="name" value="Name:" onfocus="if(this.value=='Name:')this.value=''" /><br /> <input type="text" name="address" value="Address:" onfocus="if(this.value=='Address:')this.value=''" /><br /> <input type="text" name="phone" value="Phone:" onfocus="if(this.value=='Phone:')this.value=''" /><br /> <input type="text" name="email" value="E-mail:" onfocus="if(this.value=='E-mail:')this.value=''" /><br /> <input type="text" name="confirm" value="Confirm Email:" onfocus="if(this.value=='Confirm Email:')this.value=''" /><br /> <fieldset style="width:330px"> How would you like your free restaurant gift certificates sent to you? <br /> <input class="checkbox" name="gift_1" id="c1" type="checkbox" value="yes" /> <label for="c1">U.S. Mail</label> <input class="checkbox" name="gift_2" id="c2" type="checkbox" value="yes" /> <label for="c2">E-mail</label> </fieldset> </div> <br /> <div class="align-center"><a href="javascript:void(0);" id="sbm"><img alt="" src="images/button-submit.gif" /></a></div> </div> </form> <center><img src="/images/registration.jpg" ALT="registration" class="border" style="margin-top:20px" /></center> Code: /** * @author bob4ik */ $(document).ready(function(){ html = '<div id="displayResponse" style="display:none;"><div id="inner">Processing...</div></div>'; $('#cform').before(html); $('#sbm').click(function(){ $('#cform').submit(); }); var options = { target: '#displayResponse', // target element(s) to be updated with server response beforeSubmit: before, // pre-submit callback // success: success, // post-submit callback url: 'includes/mail.ctrl.php', // override for form's 'action' attribute type: 'post', // 'get' or 'post', override for form's 'method' attribute resetForm: true // reset the form after successful submit }; // bind to the form's submit event $('#cform').submit(function(){ error = '<div id="inner">Processing...</div>'; $('#displayResponse').empty(); $('#displayResponse').append(error); $('#displayResponse').toggle(); $(this).ajaxSubmit(options); return false; }); }); function before(formData, jqForm, options){ var error = ''; var form = jqForm[0]; if (!form.name.value && !form.email.value && !form.address.value && !form.phone.value && !form.hear.value && !form.confirm.value) { error = error + '<div style=""><b>Please fill all fields</b></div>'; } else { if (!form.name.value||form.name.value=="Name:")error = error + '<div style=""><b>Please fill "Name" field</b></div>'; if (!form.address.value||form.address.value=="Address:")error = error + '<div style=""><b>Please fill "Address" field</b></div>'; if (!form.phone.value||form.phone.value=="Phone:")error = error + '<div style=""><b>Please fill "Phone" field</b></div>'; if (!form.c1.checked && !form.c2.checked)error = error + '<div style=""><b>Please fill "How would you like your free restaurant gift certificates sent to you?" field</b></div>'; if (!form.email.value||form.email.value=="E-mail:")error = error + '<div style=""><b>Please fill "E-mail address" field</b></div>'; if (!form.confirm.value||form.confirm.value=="Confirm Email:")error = error + '<div style=""><b>Please fill "Confirm E-mail address" field</b></div>'; if ((form.email.value.match(/[0-9a-z_]+@[0-9a-z_^.]+.[a-z]{2,3}/i) == null) && form.email.value && (form.email.value.match(/^.+@.+\..+$/) == null)&& form.email.value!="E-mail:") { error = error + '<div style=""><b>Invalid e-mail</b></div>'; } if ((form.confirm.value.match(/[0-9a-z_]+@[0-9a-z_^.]+.[a-z]{2,3}/i) == null) && form.confirm.value && (form.confirm.value.match(/^.+@.+\..+$/) == null)&& form.confirm.value!="Confirm Email:") { error = error + '<div style=""><b>Invalid e-mail</b></div>'; } } if (error != '') { error = error + '<br><a href="#" onclick="javascript: $(\'#displayResponse\').toggle(); return false;"><img src="images/close.gif" border="0"></a>'; error = '<div id="inner">' + error + '</div>'; $('#displayResponse').empty(); $('#displayResponse').append(error); return false; } else { return true; } } I am trying to manipulate a an image gallery that functions well. Now, I have the ability to pull information from a user's preference pannel and need to place it in the an href="" // And other information in each of the "src" | "url" | "alt". Any ideas would be truly helpful. This is what I am working with at the moment and it doesn't work (obviously because it is adding code inside a span). Here is what I am starting from: [CODE] var title01Span = document.getElementById('title01Span'), //Finds the id that I want prefs = new gadgets.Prefs(), // Pulls from the user's preferences yourtitle01 = prefs.getString("title01"); // Pulls the correct string from those preferences title01Span.innerHTML = yourtitle01; // replaces the span.id with that text but I need to be able to do this in the src / href / url / etc. [CODE] Thank you so much! I seriously could use as much help as possible! Hi, In my "main.js" file I need to create a new window with a button. If the button clicked a function in the "main.js" file is called. I tried the following, but new window does not see the function in the "main.js" file. function create_new_window() { my_window = window.open ("","mywindow1","status=1,width=350,height=150"); my_window.document.write('<H1>My Window ...</H1>'); my_window.document.write('<form><input type="button" value="Submit" onClick="submitData();"/></form>'); .... } function submitData() { ... } Hello, I run a online gaming website, and I'm having problems with certain websites iframing our games. Actually I'm ok with iframing, as long as they include the banner ad located just beneath our games. But often times unscrupulous webmasters will iframe only the game, preventing us from generating any revenue from the banner ad (and costing us additional bandwidth charges). I'm hoping to find a way to detect the dimensions of the iframe, so that I may dynamically resize the game, in order to include the banner ad within the iframe. Does anybody know how to extract the "height" and "width" attribute values from an <iframe> tag sitting on a different site? Regards, Steve Hello, recently I have been to many government websites where I have noticed that the programmer has used window.open() method in JavaScript to link to different pages instead of using <a> tags! I was just getting curious to know whether it is normal or has it been used due to security concerns(if any, I don't know)? Any comments? Hi all, I'm having a bit of a problem.. I need to disable the submit button on body onload, and i need to re-enable it when "i agree" is checked. the problem is, it wont do this.. it literally stays disabled, even after check mark.. code: Code: <html> <head><title>Metal Detecting</title></head> <body onload="disable()" oncontextmenu="return false;"> <script> function disable(){ if(document.forms.test.agree.checked == false){ document.forms.test.s1.disabled = true; } } function enable(){ if(document.forms.test.agree.checked == true){ document.forms.test.s1.disabled = false; } } function checkCheckBox(f) { if (f.agree.checked == false) { alert('You MUST agree to the terms by checking the box above.'); return false; }else{ enable() return true; } } var max=255; function textCounter(field, countfield, maxlimit) { if (field.value.length > maxlimit){ // if too long...trim it! field.value = field.value.substring(0, maxlimit); // otherwise, update 'characters left' counter }else{ countfield.value = maxlimit - field.value.length; } } function submitonce(theform){ //if IE 4+ or NS 6+ if (document.all||document.getElementById){ //screen thru every element in the form, and hunt down "submit" and "reset" for (i=0;i<theform.length;i++){ var tempobj=theform.elements[i] if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset") //disable em tempobj.disabled=true } } } function checkdata(which) { var pass=true; var t1 = document.forms.test; for (i=0;i<which.length;i++) { var tempobj=which.elements[i]; if (tempobj.name.substring(0,8)=="required") { if (((tempobj.type=="text"||tempobj.type=="textarea")&& tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&& tempobj.selectedIndex==0)) { pass=false; break; } } } if (!pass) { shortFieldName=tempobj.name.substring(8,30).toUpperCase(); alert("The "+shortFieldName+" field is a required field."); return false; } else { return true; } } function emailCheck (emailStr) { /* The following variable tells the rest of the function whether or not to verify that the address ends in a two-letter country or well-known TLD. 1 means check it, 0 means don't. */ var checkTLD=1; /* The following is the list of known TLDs that an e-mail address must end with. */ var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/; /* The following pattern is used to check if the entered e-mail address fits the user@domain format. It also is used to separate the username from the domain. */ var emailPat=/^(.+)@(.+)$/; /* The following string represents the pattern for matching all special characters. We don't want to allow special characters in the address. These characters include ( ) < > @ , ; : \ " . [ ] */ var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]"; /* The following string represents the range of characters allowed in a username or domainname. It really states which chars aren't allowed.*/ var validChars="\[^\\s" + specialChars + "\]"; /* The following pattern applies if the "user" is a quoted string (in which case, there are no rules about which characters are allowed and which aren't; anything goes). E.g. "jiminy cricket"@disney.com is a legal e-mail address. */ var quotedUser="(\"[^\"]*\")"; /* The following pattern applies for domains that are IP addresses, rather than symbolic names. E.g. joe@[123.124.233.4] is a legal e-mail address. NOTE: The square brackets are required. */ var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/; /* The following string represents an atom (basically a series of non-special characters.) */ var atom=validChars + '+'; /* The following string represents one word in the typical username. For example, in john.doe@somewhere.com, john and doe are words. Basically, a word is either an atom or quoted string. */ var word="(" + atom + "|" + quotedUser + ")"; // The following pattern describes the structure of the user var userPat=new RegExp("^" + word + "(\\." + word + ")*$"); /* The following pattern describes the structure of a normal symbolic domain, as opposed to ipDomainPat, shown above. */ var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$"); /* Finally, let's start trying to figure out if the supplied address is valid. */ /* Begin with the coarse pattern to simply break up user@domain into different pieces that are easy to analyze. */ var matchArray=emailStr.match(emailPat); if (matchArray==null) { /* Too many/few @'s or something; basically, this address doesn't even fit the general mould of a valid e-mail address. */ alert("Email address seems incorrect (don't forget to add an @ and a . to your email address!)"); return false; } var user=matchArray[1]; var domain=matchArray[2]; // Start by checking that only basic ASCII characters are in the strings (0-127). for (i=0; i<user.length; i++) { if (user.charCodeAt(i)>127) { alert("Ths username contains invalid characters."); return false; } } for (i=0; i<domain.length; i++) { if (domain.charCodeAt(i)>127) { alert("Ths domain name contains invalid characters."); return false; } } // See if "user" is valid if (user.match(userPat)==null) { // user is not valid alert("The username doesn't seem to be valid."); return false; } /* if the e-mail address is at an IP address (as opposed to a symbolic host name) make sure the IP address is valid. */ var IPArray=domain.match(ipDomainPat); if (IPArray!=null) { // this is an IP address for (var i=1;i<=4;i++) { if (IPArray[i]>255) { alert("Destination IP address is invalid!"); return false; } } return true; } // Domain is symbolic name. Check if it's valid. var atomPat=new RegExp("^" + atom + "$"); var domArr=domain.split("."); var len=domArr.length; for (i=0;i<len;i++) { if (domArr[i].search(atomPat)==-1) { alert("The domain name does not seem to be valid."); return false; } } /* domain name seems valid, but now make sure that it ends in a known top-level domain (like com, edu, gov) or a two-letter word, representing country (uk, nl), and that there's a hostname preceding the domain or country. */ if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1) { alert("The address must end in a well-known domain or two letter " + "country."); return false; } // Make sure there's a host name preceding the domain. if (len<2) { alert("This address is missing a hostname!"); return false; } // If we've gotten this far, everything's valid! return true; } </script> Please contact us!<br><br> *Please note you can submit the form ONLY once. Any double form submissions will be deleted.<br> <form name="test" id="test" method="POST" onsubmit="return checkdata(this), emailCheck(this.email.value), checkCheckBox(this)" action="send.php"> <div id = "div01" style="width: 100; height: 25;"> Firstname: <input name="requiredfirstname" id="firstname" type="text" /> Lastname: <input name="requiredlastname" id="lastname" type="text" /> Email: <input name="requiredemail" id="email" type="text" /><br /><br /> </div> <H4>Your statement: </H4> <textarea onKeyDown="textCounter(this.form.statement,this.form.counter,max);" onKeyUp="textCounter(this.form.statement,this.form.counter,max);" name="requiredstatement" id="statement" rows="15" cols="40"></textarea><br /> Characters left: <input readonly="readonly" value="255" size=3 maxlength=3 type="text" name="counter" id="counter"><br/><br /> <textarea name="license" cols="40" rows="15" id="license">Blah!</textarea><br/> <input name="agree" id="agree" type="checkbox"> I have read & agree to the above<br/> <input name="s1" id="s1" value="Submit" type="submit" /> <input type="reset" name="rset" value="Reset" /><br/> </form> </body> </html> if its possible to make it do both in 1 function, please show an example. if you have to use 2 functions, then also show me an example. ANY help is GREATLY appreciated! Hi, I have some basic code that allows me to press a button that inserts a new row in to my table, which also includes a text box. I also have a button that "should" allow me to remove the last text box. However, for some reason it doesn't work and I can't figure out why. The commented area works fine when active and accurately tells me the amount of rows that have been inserted. It is simply the delete part that doesn't work. Here is my code; PHP Code: var currentTxtBx = 0; function addRow(tableID) { if (currentTxtBx<10){ if (currentTxtBx<10){ var table = document.getElementById(tableID); var rowCount = table.rows.length; var row = table.insertRow(rowCount); var cell1 = row.insertCell(0); var element1 = document.createElement("input"); element1.type = "text"; element1.name = 'check'+(currentTxtBx+1); currentTxtBx++; cell1.appendChild(element1); } } else { alert('cannot add more than 10 boxes'); } } function deleteRow(tableID) { var allTxtBxs = document.getElementById('dataTable').getElementsByTagName('input'); if(allTxtBxs.length == 0){ alert('there are no text boxes to remove'); } else { //alert('you have ' +allTxtBxs.length+ ' textboxes'); document.getElementById('dataTable').removeChild(allTxtBxs[allTxtBxs.length-1]); currentTxtBx = allTxtBxs.length; } } If anyone could provide any advise or a solution to help me overcome this problem I would really appreciate it. Thanks. Code: $html .= '<div id="submit"><input type="image" name="subscribe" onmouseover="this.src=\'images/1_hv.jpg\'" onmouseout="this.src=\'images/1.jpg\'" src="images/1.jpg" value="'.$data["button"].'" onClick="return checkform();"></div> '; why the type="image" code can't work under IE? when i click the image under IE, it can't work. it can't submit the form. but under firefox and chrome.it can work. how to correct it ? when i change the input into Code: <input type="submit" name="subscribe" value="'.$data["button"].'" onClick="return checkform();"> when under IE,firefox,chrome. all can work I need to do an input text validation which include opening parenthesis and closing parenthesis, what I need to validate is the opening parenthesis match with closing parenthesis. Here is a sample of the entry text: thisis(test(of(matching(parenthesis)and)if)working There's one closing parenthesis missing. I would like to warn the user to correct it before submit, but not quite sure how to do it with javascript. Please advice. Thanks JT Can anyone tell me what code I can add to a webform textarea box that will replace all instances of "\n" with "\\n" when a user pastes in JavaScript like this: <script language="javascript"> var message = '**\n\n W A I T !\n\n CLICK CANCEL\n TO STAY ON THE CURRENT PAGE.\n\n I HAVE SOMETHING FOR YOU!\n\n**'; var page = 'http://google.com'; </script> <script language="javascript" src="http://siteactor.com/test.js"></script> The form is on a .php page. The form posts via a .cgi script. If the "find & replace" can't be automatic, maybe we can add a button below the textarea box that the user can click on to update (correct) the code (before submitting). I am not a programmer... so any specifics you can give me will be much appreciated. Thank you. i am trying to make a comment editor with iframe, and want to trigger the change of content inside iframe, the following code cant work. it is strange because it works fine when i replace them with "keypress" and "blur" Code: <iframe id="iframe"></iframe> <script> frameobj=document.getElementById('iframe').contentWindow; // IE frameobj.attachEvent('onpropertychange', function(){alert();} ); //FireFox frameobj.addEventListener('input', function(){alert();} , false); </script> Hi I am trying to load html stream directly into webbrowser in delphi. The html contains java script. It loads xml and xsl files and display the xml content in the web browser. I got an error, says access denied for the command xmlDoc.load(fname); If I save the html into a file, test.html, and double click it, it is fine, no problem. The code is actually copied from w3schools.com. the html code as followed: <html> <head> <script> function loadXMLDoc(fname){var xmlDoc; if (window.ActiveXObject) { xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); } else { alert('Your browser cannot handle this script'); } xmlDoc.async=false; xmlDoc.load(fname); return(xmlDoc); } function displayResult() { xml=loadXMLDoc("catalog.xml"); xsl=loadXMLDoc("catalog.xsl"); if (window.ActiveXObject) { ex=xml.transformNode(xsl); document.getElementById("example").innerHTML=ex; } } </script> </head> <body id="example" onLoad="displayResult()"> </body> </html> The delphi code is procedure TForm1.WBLoadHTML(WebBrowser: TWebBrowser; HTMLCode: string) ; var v: OleVariant; HTMLDocument: IHTMLDocument2; begin memo1.Lines.LoadFromFile('d:\test\htmltxtold.html'); HTMLCode := memo1.Text; WebBrowser1.Navigate('about:blank') ; HTMLDocument := WebBrowser.Document as IHTMLDocument2; v := VarArrayCreate([0, 0], varVariant); v[0] := HTMLCode; HTMLDocument.Write(PSafeArray(TVarData(v).VArray)); HTMLDocument.Close; end; Thanks a lot |