JavaScript - Javascript Split Method
You may have see various sites where urls are encoded by advertisement redirection service mostly by adf.ly now I want to write a personal java snippet for tor remove this spam [In opera you can specify a custom js to run at every page]
mostly the html will look like this Code: <a target="_blank" href="http://adf.ly/246619/http://www.mediafire.com/download.php?lg5z42ra13ac9hi">SteamTable App</a> I want to use .split() method as you see this part http://adf.ly/246619/ [before the second http] has to be splitted some how & url to be reinserted in the a tag. any help here Similar TutorialsHi there I'm trying to figure out what the following syntax for split means in the following line of the code arrTest[0].split('/')[0] what does ('/')[0] means in split('/')[0]? please can anyone explain Hello I have a javascript navigation bar at the top of my page. I would like to split the navigation with 3 links on the left side of my logo and 3 links on the right side. Like this.... Home Designs Services (LOGO IMAGE) About FAQ's Contact Can someone help me figure out how to split a javascript navigation? I don't know if it should be separate navigation for the right and left or if it is just a CSS change? Below is my javascript and CSS. Code: <script type="text/javascript" src="tinydropdown.js"></script> </script> <div class="nav"> <ul id="menu" class="menu"> <li class="nodiv"><a href="#">Home</a></li> <li><a href="#">Designs</a> <ul> <li><a href="#">One</a></li> <li><a href="#">Two</a></li> <li class="submenu"> <a href="#">Three</a> <ul> <li class="noborder"><a href="#">One</a></li> <li><a href="#">Two</a></li> <li><a href="#">Three</a></li> </ul> </li> </ul> </li> <li><span>Services</span> <ul> <li><a href="#">One</a></li> <li><a href="#">Two</a></li> <li><a href="#">Three</a></li> <li class="submenu"> <span>No Link</span><ul> <li class="noborder"><a href="#">One</a></li> <li><a href="#">Two</a></li> <li><a href="#">Three</a></li> <li><a href="#">Four</a></li> <li><a href="#">Five</a></li> </ul> </li> <li><a href="#">Five</a></li> <li><a href="#">Six</a></li> </ul> </li> <li class="nodiv"><a href="#">About</a></li> <li><a href="#">FAQ's</a> <ul> <li><a href="#">One</a></li> <li><a href="#">Two</a></li> <li class="submenu"> <a href="#">Three</a> <ul> <li class="noborder"><a href="#">One</a></li> <li><a href="#">Two</a></li> <li><a href="#">Three</a></li> </ul> </li> </ul> <li class="nodiv"><a href="#">Contact</a></li></li> </li> </ul> </div> <script type="text/javascript"> var dropdown=new TINY.dropdown.init("dropdown", {id:'menu', active:'menuhover'}); </script> Code: .nav { height:36px; color:#fff; text-shadow:1px 1px #888; position:absolute; z-index: 100; width: 960px; padding-top: 70px; padding-left: 0px; } .menu a { float:left; color:#eee; text-decoration:none; width:120px; height:28px; padding-top:8px; } .menu span { float:left; color:#eee; text-decoration:none; width:120px; height:28px; padding-top:8px; } .menu a:hover { color:#fff; } .menu { list-style:none; font:16px Arial,Verdana; text-align:center; width:900px; margin:0 auto; } .menu li { position:relative; float:left; width:120px; z-index:1000; } .menu ul { display:none; position:absolute; font:normal 13px Arial,Verdana; top:36px; left:0; background:#aaa; display:none; list-style:none; } .menu ul li { float:none; border-top:1px solid #ccc; width:120px; } .menu ul li a, li.menuhover li a, li.menuhover li.menuhover li a { float:none; display:block; background:none; height:22px; padding-top:5px; } .menu ul li a:hover, li.menuhover li a:hover, li.menuhover li.menuhover li a:hover {background:#999; color:#fff; } .menu ul li span, li.menuhover li span, li.menuhover li.menuhover li span { float:none; display:block; background:none; height:22px; padding-top:5px; } .menu ul ul { left:120px; top:0; } .menu li.submenu { font-weight:bold; } .menu li.noborder { border-top:none; } li.menuhover a, li.menuhover li.menuhover a { color:#fff; background:#999; } li.menuhover span, li.menuhover li.menuhover span { color:#fff; background:#999; } THANKS! Whats wrong with the code below? I'm trying to get the email service provider name. Code: <html> <head> <script type="text/javascript"> function GetProvider { var fullemail = openinviter.email_box.value; var afterat = fullemail.split("@"); var Provider = afterat[1].split("."); var showit = Provider[0]; openinviter.provider_box.value=showit; } </script> </head> <body> <form action="" method="post" name="openinviter"> <input type="text" name="email_box" onchange="GetProvider()" /> <input type="text" name="provider_box" value=""> </form> </body> </html> Thanks alot! would it be better to place the javascript into a .js file or just place the js code somewhere else in the html? How should it look? Code: <div style="width: 225px; height: 155px; float: left; height: 16px; background-color: #000000; color: #FFFFFF; margin-left: 0px; margin-bottom: 0px; font-size: small; padding-left: 0px;"> <img alt="" src="images/news.png" height="16" width="222" /><div style="width: 225px; height: 155px; float: left;"><script type="text/javascript">// <![CDATA[if(document.layers){document.write('<ilayer id="ns4div" width="'+swidth+'" height="'+sheight+'" bgcolor='+sbcolor+'><div id="ns4div1" width="'+swidth+'" height="'+sheight+'" onmouseover="sspeed=0;" onmouseout="sspeed=rspeed"></div></ilayer>')} if(document.getElementById||document.all){document.write('<div style="position:relative;overflow:hidden;width:'+swidth+'px;height:'+sheight+'px;clip:rect(0 '+swidth+'px '+sheight+'px 0);background-color:'+sbcolor+';" onmouseover="sspeed=0" onmouseout="sspeed=rspeed"><div id="iens6div" style="position:relative;width:'+swidth+'px;"></div></div>');} // ]]></script> </div></div> Hello, i wrote this code, But is not working, i want to use onChange event and redirect user into a url accordingly. this is my code; <script type="text/javascript"> function goto() { var URL = document.frmsort.optsort.options[document.optsort.optsort.selectedIndex].value; window.location.href = URL; } </script> <form id="frmsort" name="frmsort" action="http://localhost/APP/category.php" method="post"> <select name="urls" onChange="goto()"> <option value="http://localhost/APP/category.php?sub=1">-- choose option --</option> <option value="http://localhost/APP/category.php?sub=1&sort=1">OP1</option> <option value="http://localhost/APP/category.php?sub=1&sort=2">OP2</option> </select> </form> I really appreciate your help... thank you... Hey peeps, I'm trying to use wget to access this website that uses javascript. The website is from my work. Basically I made a program that parses information from our payment page. It tells me how much I am being paid for the month. Anywho, the variables on the page are in javascript, and thats one language I'm not proficient at. I need to change the month that it gets the pay for. The default is the current month. But it can be changed to last month, and from the code I can tell that something has to be changed from "THIS_MONTH" to "LAST_MONTH", but I'm not sure how to properly do it. Posted below is the source code from the website. Please let me know how I can change that without actually having to click the button to change the scope to last month. And also, is there any way to change this in the post method, or any other method that wget uses? I only included the parts I thought could be relevant. Thanks guys! BTW, I think it pertains with g_FiltersMenuStr Code: <title>SupportSpace - Tech Support for Computers, Printer, Security, Gadgets...</title> <meta name = "description" content = "get immediate tech support for your PC / Computer, Printers, Outlook / Email Setup, Wireless, Networking, Anti-Virus & Security, Spyware, XP, Vista, I-Pod, MP3 Player Setup, Zune, Printer Setup, Backup Services for your Documents & Many other online live support"/> <meta name = "keywords" content = "online live tech support PC Computer Printers Outlook Email Setup Wireless Networking AntiVirus Security Spyware XP Vista IPod MP3 Player Zune Printer Setup Backup Services hardware software help chat"/> <meta name = "language" content = "English"/> <link REL="SHORTCUT ICON" HREF="/support/images//icons/shortcut_icon.ico"/> <script type="text/javascript">if(!JAWR){var JAWR = {};};;JAWR.jawr_dwr_path='/support/dwr';JAWR.dwr_scriptSessionId='CCA333F742C70F495236AA2C97D653D2';JAWR.app_context_path='/support';</script> <link rel="stylesheet" type="text/css" media="screen" href="/support/styles/31289092/bundles/common_connection.css" /> <link rel="stylesheet" type="text/css" media="screen" href="/support/styles/1893248551/bundles/sessionHistory.css" /> </head> <script type="text/javascript">if(!JAWR){var JAWR = {};};;JAWR.jawr_dwr_path='/support/dwr';JAWR.dwr_scriptSessionId='BF92335E3E86FC7586F1F5BFB96E81FB';JAWR.app_context_path='/support';</script> <script type="text/javascript" src="/support/scripts/122785183/bundles/common.js" ></script> <body class="supportspace"> <script type="text/javascript"> var jabberConnectorSrc = "/support/extra_scripts/1.23a1.6/flashconnector/jabberConnector.swf"; if (!!(window.attachEvent && !window.opera)){ document.write('\ <OBJECT id="jabberConnector" dontRewriteMe=true codeBase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" height="1" width="1" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000">\ <PARAM value="'+jabberConnectorSrc+'" name="Src" />\ </OBJECT>'); } else{ document.write('<embed swliveconnect="true" name="jabberConnector" id="jabberConnector" src="'+jabberConnectorSrc+'" quality=low height="1" width="1" type="application/x-shockwave-flash"></embed>'); } </script> <!--[if lt IE 7]> <style> #dSSLogo{position:relative} </style> <![endif]--> <div id="dHeader"> <div id="dHeader_1" class="center s2DarkGray"> <div id="dSSLogo" onclick="document.location = 'http://www.supportspace.com/support/'"></div> <div class="rightLinks"> <div id="dHeaderLinks" style='display:none;' class='invisible'> <div class="dHeaderLink"><a class="mainlevel-trans" href="javascript:void(0);" id="dSigninMenu">Sign In</a></div> <div class="dHeaderLinksSep">|</div> <div class="dHeaderLink"><a class="mainlevel-trans" href="https://www.supportspace.com/support/affiliates.s2?aiu=UserRegistration" id="headerSecondMenu">Register</a></div> <div class="dHeaderLinksSep">|</div> <div class="dHeaderLink"><a class="mainlevel-trans" href="http://corporate.supportspace.com/about_us">About Us</a></div> <div class="dHeaderLinksSep">|</div> <div class="dHeaderLink"><a class="mainlevel-trans" href="http://www.supportspace.com/support/faq.s2" id="menuHelp">Help</a></div> </div> <div id="dHeaderLinksAfterLogin" class='visible'> <div id="dHeaderMailNotification"> <a id="nomailNotification" class="s2LightGray nounderline" href="http://www.supportspace.com/support/inbox.s2">(<span class="nbNewOfflineMessagesHeader">0</span>) <img src="/support/images/offline_messages/message_icon_grey_16x14.gif" alt="" title="" width="16" height="14" align="absmiddle" border="0"/></a> <a id="mailNotification" style="display:none" class="s2Blue nounderline" href="http://www.supportspace.com/support/inbox.s2">(<span class="nbNewOfflineMessagesHeader">0</span>) <img src="/support/images/offline_messages/message_icon_blue_16x14.gif" alt="" title="" width="16" height="14" align="absmiddle" border="0"/></a> </div> <div id="dHeaderWelcome" class="dHeaderWelcome">Hello </div> <div style="float:left;"> <table cellpadding=0 cellspacing=0 border=0> <tr> <td width="5">|</td> <td> <a id="dMySpaceMenu" class="mainlevel-trans" href="#">My Account</a> <ul id="dMySpaceMenuContent" class="menu" style="display:none;"></ul> </td> <td width="5">|</td> <td><a id="dSignOut" class="mainlevel-trans" href="http://www.supportspace.com/support/j_spring_security_logout">Sign Out</a></td> <td width="5">|</td> <td><a class="mainlevel-trans" href="http://corporate.supportspace.com/about_us">About Us</a></td> <td width="5">|</td> <td><a id="menuHelpAfter" class="mainlevel-trans" href="http://www.supportspace.com/support/faq.s2">Help</a></td> </tr> </table> </div> </div> </div> <div style="clear:both;"></div> </div> <div id="dHeader_2" class="center"> <div id="dHeaderMenus"> <div> <a href="http://www.supportspace.com/support/" onclick="this.blur()" title="SupportSpace homepage" tabindex="1" id="menuHome"> <img src="/support/images/header/home_btn_regular.gif" alt="" width="127" height="32"/> </a> </div> <div> <a href="http://www.supportspace.com/support/expert" onclick="this.blur()" id="menuExperts" title="Search for online experts"> <img src="/support/images/header/experts_btn_regular.gif" alt="" width="127" height="32"/> </a> </div> <div> <a href="http://www.supportspace.com/support/services" onclick="this.blur()" id="menuPackages" title="Search for featured support services"> <img src="/support/images/header/services_btn_regular.gif" alt="" width="127" height="32"/> </a> </div> </div> <div id="dSearchBox"> <div id="dSearchBoxQuery"> <input type="text" id="searchBoxQuery" style="color:#7C7C7C" name="searchBoxQuery" value="Search" onkeypress="submitEnter(this,event,runExternalSearch)"> </div> <div id="dSearchBoxGo"> <img id="dSearchBoxGoBtn" width="22" height="22" border="0" alt="Search" src="/support/images/header/search_icon_regular_22x22.gif" onmouseout="this.src='/support/images/header/search_icon_regular_22x22.gif'" onmouseup="this.src='/support/images/header/search_icon_regular_22x22.gif'" onmouseover="this.src='/support/images/header/search_icon_mouse_over_22x22.gif'" onmousedown="this.src='/support/images/header/search_icon_pressed_22x22.gif'" /> </div> <div style="clear:both;"></div> </div> </div> <div class="clearboth"></div> </div> <div id="dTemplateBody" class="center"> <table border="0" cellpadding="0" cellspacing="0"> <tr> <td class="leftPanel" > <div > <div class="getHelp box"> <div class="title"><img src="/support/images/header/menu_get_help.gif" width="170" height="27" alt="Get help on products"></div> <div class="s2Gray productList content"> <ul> <li class="product ellipsis"><a class="linkOnHover" href="http://www.supportspace.com/support/category/Virus_-_Spyware" title="Virus - Spyware">Virus - Spyware</a></li> <li class="product ellipsis"><a class="linkOnHover" href="http://www.supportspace.com/support/category/Printers" title="Printers">Printers</a></li> <li class="product ellipsis"><a class="linkOnHover" href="http://www.supportspace.com/support/category/PC_Support" title="PC Support">PC Support</a></li> <li class="product ellipsis"><a class="linkOnHover" href="http://www.supportspace.com/support/category/Windows" title="Windows">Windows</a></li> <li class="product ellipsis"><a class="linkOnHover" href="http://www.supportspace.com/support/category/Security" title="Security">Security</a></li> <li class="product ellipsis"><a class="linkOnHover" href="http://www.supportspace.com/support/category/Backup" title="Backup">Backup</a></li> <li class="product ellipsis"><a class="linkOnHover" href="http://www.supportspace.com/support/category/PC_to_PC_Transfer" title="PC to PC Transfer">PC to PC Transfer</a></li> <li class="product ellipsis"><a class="linkOnHover" href="http://www.supportspace.com/support/category/Wireless_Network" title="Wireless Network">Wireless Network</a></li> <li class="product ellipsis"><a class="linkOnHover" href="http://www.supportspace.com/support/category/Email_and_Internet" title="Email and Internet">Email and Internet</a></li> <li class="product ellipsis"><a class="linkOnHover" href="http://www.supportspace.com/support/category/Browsers" title="Browsers">Browsers</a></li> <li class="product ellipsis"><a class="linkOnHover" href="http://www.supportspace.com/support/category/iPod_and_MP3" title="iPod and MP3">iPod and MP3</a></li> <li class="product ellipsis"><a class="linkOnHover" href="http://www.supportspace.com/support/category/Camera_-_Photo" title="Camera - Photo">Camera - Photo</a></li> <li class="product ellipsis"><a class="linkOnHover" href="http://www.supportspace.com/support/category/Mobile_Phones" title="Mobile Phones">Mobile Phones</a></li> <li class="product ellipsis"><a class="linkOnHover" href="http://www.supportspace.com/support/category/Green_PC" title="Green PC">Green PC</a></li> </ul> </div> </div> <div class="box howdoesitwork s2Gray"> <div class="title"> <img src="/support/images/left_pannel/menu_how_it_works_170x43.gif" width="170" height="43" alt=" "> </div> <div class="steps"> <table width="100%" cellpadding="0" cellspacing="0"> <tr> <td><img src="/support/images/left_pannel/3_steps_1_icon_55x60.gif" width="55" height="60" alt=""/></td> <td valign="top"> <p><span class="title bold">1.Choose</span><br/> a service or an online expert.</p> </td> </tr> <tr height="5"></tr> <tr> <td><img src="/support/images/left_pannel/3_steps_2_icon_55x60.gif" width="55" height="60" alt=""/></td> <td valign="top"> <p><span class="title bold">2.Connect</span><br/> to the expert and watch your problem being solved.</p> </td> </tr> <tr height="5"></tr> <tr> <td><img src="/support/images/left_pannel/3_steps_3_icon_55x60.gif" width="55" height="60" alt=""/></td> <td valign="top"> <p><span class="title bold">3.Done</span><br/> Relax and rate your experience.</p> </td> </tr> </table> </div> </div> </div> </td> <td class="panelSpacer" > </td> <td class="rightPanel" > <div id="dBodyPage" class="bodyPage" > <script type="text/javascript" src="/support/scripts/N1461701270/bundles/session_history.js" ></script> <script type="text/javascript"> var gExternalParameterType = ""; var gSupportSessionId = ""; var gIsSupporter = true; var gError = false; var gExternalSessionFatalError = true; var gDefaultFilterList = {}; gDefaultFilterList['SESSION_DATE'] = ""; gDefaultFilterList['SESSION_STATUS'] = ""; gDefaultFilterList['SESSION_TYPE'] = ""; gDefaultFilterList['SUPPORT_SESSION'] = ""; gDefaultFilterList["SESSION_DATE"] = "THIS_MONTH"; gDefaultFilterList["SESSION_TYPE"] = "PAID"; var gSHistoryStrings = { error_feedback_add:"You cannot add feedback to this session.", error_feedback_fatal:"Required session is not availible. You cannot add feedback.", error_session_report_add:"You cannot edit the solution report for this session.", error_session_report_fatal:"Required session is not available. You cannot edit the solution report." } var g_FiltersMenuStr = { "SESSION_DATE":"Date", "SESSION_DATE.TODAY":"Today", "SESSION_DATE.YESTERDAY":"Yesterday", "SESSION_DATE.THIS_WEEK":"This week", "SESSION_DATE.LAST_WEEK":"Last week", "SESSION_DATE.THIS_MONTH":"This Month", "SESSION_DATE.LAST_MONTH":"Last month", "SESSION_DATE.LAST_6_MONTH":"Last 6 months", "SESSION_DATE.THIS_YEAR":"This year (2011)", "SESSION_DATE.LAST_YEAR_AND_EARLIER":"Earlier than (2011)", "SESSION_STATUS":"Status", "SESSION_STATUS.UNRESOLVED":"Unresolved", "SESSION_STATUS.ENDED_BEFORE_PAYMENT":"Ended before payment", "SESSION_STATUS.FORWARDED":"Forwarded", "SESSION_STATUS.DISPATCHED":"Dispatched", "SESSION_STATUS.RESOLVED":"Resolved", "SESSION_STATUS.UNCOMPLETED":"Uncompleted", "SESSION_STATUS.IN_PROGRESS":"In progress", "SESSION_STATUS.LEFT_OPEN":"Left Open", "SESSION_TYPE":"Type", "SESSION_TYPE.PAID":"Paid", "SESSION_TYPE.FREE_COUPON":"Free (Coupon)", "SESSION_TYPE.FREE_EXPERT":"Free (Expert)", "SUPPORT_SESSION":"Current Support Session", "DEFAULT_FILTER_MENU":"Back to default", "NO_FILTERS_MENU":"Clear all filters", "NO_FILTERS_NOTE":"No filters (All sessions)" }; var gSessionFeedbackHistoryUrl = "/support/sessionFeedbackHistory.s2"; var gSessionHistory = "/support/sessionHistory.s2"; var gSessionHistoryUrls = { filter_empty:"http://images.supportspace.com/support/images/common/empty.gif", filter_X:"http://images.supportspace.com/support/images/session_history/filter_X_mark.gif", filter_V:"http://images.supportspace.com/support/images/session_history/filter_V_select.gif", filter_arrow_white:"http://images.supportspace.com/support/images/session_history/filter_arrow_white.gif", filter_arrow_grey:"http://images.supportspace.com/support/images/session_history/filter_arrow_grey.gif" } var g_experts; </script> <div id="dSHistoryPage"> <div class="dSmallPreloaderContainer"><div id="dSmallPreloader" style="display:none;"><img src="http://images.supportspace.com/support/images//common/preloader_16x16.gif" alt=""></div></div> <h1 style="float:left">Session History</h1> <div class="clearboth"></div> <div id="dSHistoryContent"> <div id="dListBar" class="listBar"> <div id="dFiltersMenuButton">Filtered by: <img src="/support/images/session_history/filter_arrow_down.gif" alt=""/></div> <div id="dFiltersSelected"></div> <div class="displayedCounter">Displaying: 38</div> </div> <div id="dFiltersMenuContent"><div id="dFiltersMenuDivToReplace"></div></div> <div class="clearboth"></div> <div id="dSHistoryResults"> <script type="text/javascript"> var gSelectedFilters = {}; gSelectedFilters['SESSION_DATE'] = ""; gSelectedFilters['SESSION_STATUS'] = ""; gSelectedFilters['SESSION_TYPE'] = ""; gSelectedFilters['SUPPORT_SESSION'] = ""; gSelectedFilters["SESSION_DATE"] = "THIS_MONTH"; gSelectedFilters["SESSION_TYPE"] = "PAID"; (function(){ var dDisplayedCounter = $("dListBar") ? $("dListBar").down(".displayedCounter") : null; if(dDisplayedCounter){ dDisplayedCounter.update("Displaying: 38"); } }).defer(); var gSolutionReport; </script> <div class="dThreads"> <div id="dSessionHistoryError" style="display:none;"></div> <script type="text/javascript"> if (typeof(window.g_experts) == "undefined" || !window.g_experts){ window.g_experts = []; window.gIsAnExpertIsOnline = false; } g_experts.push({ id:193037, supporterDynamicDetails:{ online4Customer:{ customer:{ id:"" }, customerCookie:"" }, supporterDisplayPresenceStatusForExpectedCustoemr:"online", supporterDisplayPresenceStatus:"online" }, displayUserName:"", jabberUsername:"23a9ea173c4a7923ef41c9d6afa208d36ea1900f", photoUri:"193037_1273126504113.gif" }); </script> I use this code in a form that posts to two different destinations, I use JavaScript to achieve it. Code: <SCRIPT type="text/javascript"> function submitTo(where) { document.form.action = where; document.form.submit(); } </SCRIPT> <FORM action="" method="post" name="form"> <DIV> <INPUT onClick="return submitTo('1.html')" type="button" value="1"> <INPUT onClick="return submitTo('2.html')" type="button" value="2"> </DIV> </FORM> I am still wanting to do is the same thing, but with drop down menu's (SELECT) instead of INPUT. Is there anyone clever that can think of a solution? I'm still trying to work on it, but haven't thought of anything up yet.. I'm designing a page that uses javascript+css for enhanced interaction. However, if javascript is disabled, I'd still like the page to be functional, albeit less fancy. Likewise, if css is disabled, it still needs to be functional. Finally, if both js+css are disabled, the page will be quite bare but still usable. For example, I use javascript to set a css style that hides certain panels of content. JS is used to toggle these and all is fine. If JS is disabled, then the css isn't applied, and all the content is visible (though not too pretty). If CSS is disabled, the inline CSS applied by the JS works fine. Finally, if both are disabled, all the content is visible. I'm wondering what's the best way to do this. Currently, I set the styles like this in the js file: Code: function initialize() { // set styles, for example: document.getElementById("panel").style.display = "none"; } var onloadFlag = false; document.onreadystatechange = function() { if (!onloadFlag) { onloadFlag = true; initialize(); } }; // for older browsers window.onload = function() { if (!onloadFlag) { onloadFlag = true; initialize(); } }; The problem that sometimes comes up is I see the "fallback" styles briefly, before the JS kicks in and applies the enhanced css. How can I avoid this? Hi , I am inserting an image into a span tag by click on button and resize the image using resize_image_height_weight function. I am using two function to do this task. setImage setImage_w3Validation setImage function resize the image but fail on w3validation on my webpage( As per w3c there is no attribute onload for image tag.) To fix out this issue I am using setImage_w3Validation function which pass on w3validation but unable to call resize_image_height_weight function. My purpose is to resize the image. Kindly suggest me how to do it? <html> <head> <script TYPE="text/javascript" language="javascript"> function resize_image_height_weight(id, hgt, wdth){ //alert(id); Obj=document.getElementById(id); myImage = new Image(); myImage.src = Obj.src; var heights = myImage.height; var widths = myImage.width; // alert("Height=>" + heights + " Width=> " + widths); if(heights > hgt || widths > wdth) { if(heights > widths) { var temp = heights/hgt; var new_width = widths / temp; new_width = parseInt(new_width); heights = hgt; widths = new_width; } else { var temp = widths/wdth; var new_height = heights / temp; new_height = parseInt(new_height); heights = new_height; widths = wdth; } } Obj.height = heights; Obj.width = widths; } function setImage(){ document.getElementById("IM0").innerHTML ="<center><img src=\"http://www.google.co.in/intl/en_com/images/srpr/logo1w.png\" id=\"img1\" alt=\"\" height=\"125\" width=\"125\" onload=\"resize_image_height_weight('img1',125,125);\"><\/center>"; } function setImage_w3Validation(){ document.getElementById("IM1").innerHTML ="<center><img src=\"http://www.google.co.in/intl/en_com/images/srpr/logo1w.png\" id=\"img2\" alt=\"\" height=\"125\" width=\"125\"><script type=\"text/javascript\">document.getElementById('img2').onload = function(){resize_image_height_weight('i12',125,125);};<\/SCRIPT><\/center>"; //I wanna to do the task using this one function to resize img for w3validation } function clear_page(){ document.getElementById("IM0").innerHTML =""; document.getElementById("IM1").innerHTML =""; } </script> </head> <body> <div class="img3"><span id="IM0"></span></div> <div class="img3"><span id="IM1"></span></div> <input type="button" name="btn1" value="Image Onload W3C Fail" onclick="setImage();"> <input type="button" name="btn2" value="Image Onload W3C Pass" onclick="setImage_w3Validation();"> <input type="button" name="btn2" value="Clear" onclick="clear_page();"> </body> </html> Why is the callwhy is the slice method only a method of an Array instance? The reason why I ask is because if you want to use it for the arguments property of function object, or a string, or an object, or a number instance, you are forced to use Array.prototype.slice.call(). And by doing that, you can pass in any type of object instance (Array, Number, String, Object) into it. So why not just default it as a method of all object instances built into the language? In other words, instead of doing this: Code: function Core(){ var obj = {a : 'a', b : 'b'}; var num = 1; var string = 'aff'; console.log(typeof arguments);//Object console.log(arguments instanceof Array);//false var args1 = Array.prototype.slice.call(arguments); console.log(args1); var args2 = Array.prototype.slice.call(obj); console.log(args2); var args3 = Array.prototype.slice.call(num); console.log(args3); var args4 = Array.prototype.slice.call(string); console.log(args4); Core('dom','event','ajax'); Why not just be able to do this: Code: function Core(){ var obj = {a : 'a', b : 'b'}; var num = 1; var string = 'aff'; var args = arguments.slice(0); var args2 = obj.slice(0); var args3 = num.slice(0); var args4 = string.slice(0); //right now none of the above would work but it's more convenient than using the call alternative. } Core('dom','event','ajax'); Why did the designers of the javascript scripting language make this decision? Thanks for response. 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. Code: dropDownPart.innerHTML = tmpInnerHTML; how does this tmpInnerHTML gets filled : Code: for (var i = 0; i < arr.length ; i++) { var arr1 = arr[i].split('|'); id_tezaver = arr1[0]; term = arr1[1] // if arr1[1] contains ', then ewerything after that disapears inside term, // like "bird's eyes" becomes "bird" // how to handle that ? // bad example how I get to verify that the stuff is complete inside array // term = arr1[1].replace(/'/i, /oo/); } Hi, I am very new to javascript (been learning over the last 2 days) and I am trying to: 1. create a form that will allow a user to input area codes separated by commas (102,103,209,204,...) 2. remove the commas from the string and store the values in array 3. validate that the values are area code format (ie; greater than 99 but less than 1000) 4. remove any duplicate values before sending to the server I am more or less doing this just to learn (I have ideas for future apps) but know very little about programming. Thank you in advance for any help. The code I have written so far (please excuse the poor programming. I am very new )... Code: <html> <head> <script language="javascript"> function ValidAreaCode(AreaCode) { for(i=0;i<AreaCode.length;i++); var AreaCode = new Array(); AreaCode=input.split(","); function validate() { var n=document.getElementById("myText").value; if(n<99 || n >1000) alert("Please enter a valid area code."); } } //Remove Duplicates var arr = AreaCode(); var unique = arr.unique(); alert(unique); function unique(a) { var r = new Array(); o:for(var i = 0, n = a.length; i < n; i++) { for(var x = 0, y = r.length; x < y; x++) { if(r[x]==a[i]) continue o; } r[r.length] = a[i]; } return r; } </script> </head> <FORM name="MyForm"> Enter area codes with a "," in between them: <input type="text" id="myText"> <input type="submit" value="Submit" onClick="ValidAreaCode()" id="myText"> <P> </form> <br/> </html> Hi, I'm working on refining my search function. At the moment it works fine like this: Code: function searchLocations() { var found = false; var input = document.getElementById('autocomplete').value; for (var j = 0; j < gmarkers.length; j++) { if (gmarkers[j].myname.toLowerCase() == input.toLowerCase()) { found = true; gmarkers[j].show(); myclick(j); } } if ( ! found ) alert("No matches found. Please check your spelling or refine your search."); } but you have to get the input exactly the same as it is in the array for it to work (as it should, being that that's the way it's written). I wanted to split it so that for example Black Cat Hotel would pop if the user entered Black OR Cat OR Hotel (or any combination of the above). So I thought that this might work: Code: function searchLocations() { var found = false; var input = document.getElementById('autocomplete').value; for (var j = 0; j < gmarkers.length; j++) { var s = gmarkers[j].myname.toLowerCase().split(" "); if ( s == input.toLowerCase()) { found = true; gmarkers[j].show(); myclick(j); } } if ( ! found ) alert("No matches found. Please check your spelling or refine your search."); } but obviously not. Is there some better way to do this? I have var att=7,8,9 how can I convert these to an array so I can loop through the values? Hi, I am inserting fields from a .csv file into database using integration engine(rhapsody) there is a javascript filter where I am trying to catch rows that have extra commas in the field text. Tried using the following code but the rows with extra commas just error and don't get inserted. Code: // Loop through all the input messages for (var i = 0; i < input.length; i++) { var next = output.append(input[i]); // Get the body of the current input message var body = input[i].text; // Set the body next.text = body; var name =next.getProperty("BaseFilename"); var fields = name; var fieldsList = fields.split(/\s*,\s*/); if (fieldsList.length >= 10) { name="error"+i; input.setProperty("BaseFilename", name ); } } I really don't understand JavaScript... xD Code: var inputDate = "<?php echo $inputDate2; ?>"; var JDates = new Array(); Jdates = inputDate.split("/"); var currentDate = new Date(parseInt(Jdates[2]), parseInt(Jdates[0])-1, parseInt(Jdates[1])); So... when creating 'currentDate' Jdates[0] will equal 0, even though I just asked javascript to split the inputDate by all "/". The inputDate var equals "08/06/2010" before the split. Any help greatly appreciated! Hey I'm trying to create an aggregates calculator where the sum & average are calculated from the user inputs textarea of values, which i have split(). This is my code so far. I'm sure I'm not using the variables or parseFloat method correctly. Any advise? Many Thanks <html> <head> <script type="text/javascript"> <!-- function add() { document.getElementById("answer").value+=(document.getElementById("num1").value) + '\n'; } function calculate() { var total = "sa"; var sa = textAreaText.split("\n"); for (var i=0; i < sa.length; i++) parseFloat(sa[i]) + total; { document.getElementById("sum").value = total; } { document.getElementById("average").value = total / sa.length; } } //--> </script> </head> <body> <h1>Aggregates</h1> <h3>Add as many numbers as you like<br>to the list,then click Calculate.</h3> <form name="entryForm" id="entryForm"> <input type="text" id="num1"></input> <input type="button" value="Add to list" onclick="add();"><br> <textarea name="text" rows="15" cols="20" readonly="readonly" id="answer"></textarea><br> <input type="button" value="Calculate" onclick="calculate"> <input type="reset" value="Reset"> <p>Total (Sum);</p> <input type="text" id="sum" value="0"><br> <p>Average :</p> <input type="text" id="average" value="0"> </form> </body> </html> is there any smart way to do split, and ignore certain delimiters, like: Code: var s = "don't use ',' as part of data, some other text"; arr = s.split(","); // obviously don't want s to be splitted at ',' except chanhing delimiter ... ? I have a web form that requests a user full name and email address. What I would like to do is when the user fills in the full name in one input box, I would like to take the full name and populate the email address field as such. "first.last@allstate.com". So pretty much split the full name and popluate email address field "first.last@allstate.com". Tracy |