Easier Way To Shorten The? Code
Jul 28, 2010
I tried using the "For Loop" function to accomplish this but I couldn't get it to work. show me an easier way to shorten this code up
Code:
function normal()
{
var welcomelink = document.getElementById("welcomelink");[code].....
I did try to recode everything so that the link/content and sublink/content would follow a numerical sequence...e.g. link1/content1, link2/content2, link3/content3, sublink1/subcontent1, sublink2/subcontent2, sublink3/subcontent3...etc. and then use the for...loop function but again it failed on me.
View 5 Replies
ADVERTISEMENT
Feb 11, 2011
I'm still learning this scripting thing. Is there any way to shorten this lengthy code. I know there is, just not sure what i'm looking for?
PA1_10ST
PA11_20ST
PA21_30ST[code].....
View 4 Replies
View Related
Apr 22, 2009
How can I shorten the output of the title in this JS code?
<script language="" type="text/javascript">
<!--
for (x = 0; x < 3; x++)[code].....
I need to shorten the "+threads[x].title+" sometimes the titles created by users are too long and is messed up the page display
View 3 Replies
View Related
Sep 9, 2007
a common task when writing multi-use functions, is deciphering the type of data passed to the function.
Javascript's built-in data identification methods complicate function writing, by imposing a "20 questions" style interogation to determine the actual, useful to a programmer, type.
they also slow down functions, requiring both a function execution and a comparision operation upon every type guess.
a common method is something like:
if(typeof x=='string'){ };
but this has several limitations. for example:
x=[1,2,3];
typeof x; //returns 'object'
safely catching an undefined is often done like:
if(typeof x != 'undefined' ){ };
my function making got a lot easier after writing these simple prototypes:
String.prototype.type="string";
Array.prototype.type="array";
Number.prototype.type="number";
Boolean.prototype.type="boolean";
Date.prototype.type="date";
Object.prototype.type="object";
RegExp.prototype.type="regexp";
Function.prototype.type="function"
if(!!window.XML)XML.prototype.type="xml";
String.prototype.isString=1;
Array.prototype.isArray=1;
Number.prototype.isNumber=1;
Boolean.prototype.isBoolean=1;
Date.prototype.isDate=1;
Object.prototype.isObject=1;
RegExp.prototype.isRegExp=1;
Function.prototype.isFunction=1;
if(!!window.XML)XML.prototype.isXML=1;
the result?
shorter simpler code.
examples:
// smarter object typin':
[1,2,3].type; //returns 'array'
//when expecting a string or array possibility:
y=x.isString?x:x.join();
//more-flexible event handling:
function doBold(elm){ //accepts element object or id string...
if(elm.isString){elm=document.getElementById(elm);}
elm.style.fontWeight="bold";
}//end doBold
// detect an undefined variable:
if( ! x.type){ alert('x is undefined')};
by tucking the protos in your script file, you get simpler, faster-executing code. (for a tiny bit of overhead)
if script length is of upmost concern (as in a bookmarklet), these smaller protos give you simpler typing: (without the speed benefits...)
Object.prototype.type=function(){return typeof this;};
//usage:
switch(x.type()){
case 'string': return x;
case 'date': return x.toLocaleString();
case 'array': return x.join('
');
default: return x.toString();
}//end switch;
//another one:
Object.prototype.isType=function(strType){return (!! typeof this === strType)};
//usage:
x=101;
x.isType('string'); //returns false
x.isType('number'); //returns true
View 12 Replies
View Related
Jul 20, 2005
I have a js script that changes the visibilty of a selected span to "visible", but makes sure that no other related spans are visibile to the user by hiding everything first....
View 1 Replies
View Related
Feb 15, 2004
These are a couple little bookmarklets that make testing your pages easier.
This is for adjusting resolution.
<script>
javascript:external.AddFavorite('javascript:void(m=window.open("","m","height=30,width=150"));m.focus();m.document.write('<form><select onchange="opener.eval(this[this.selectedIndex].value)"><option value=""><option value="self.resizeTo(640,480)">640x480<option value="self.resizeTo(800,600)">800x600<option value="self.resizeTo(1024,768)">1024x768</select></form>')','Resize')
</script>
This is for running selected code. You select the code then open the bookmark. (I used it testing this post.)
<script>
javascript:window.external.AddFavorite('javascript:void(window.open("javascript:document.write(opener.document.selection.createRange().text);document.close()"))','Run Code Selected')
</script>
Turn borders on to see table layout.
<script>
javascript:window.external.AddFavorite('javascript:void(t=document.getElementsByTagName("table"));for(i=0;i<t.length;i++){void(t[i].border="1")}','Borders On')
</script>
I use them regularly hope they're usefull to you.
View 8 Replies
View Related
Dec 16, 2009
I have in javascript a text say I am an idiot
I want to do it. "I am...." and on mouseover it shows up I am an idiot.
How can I do it?
View 4 Replies
View Related
Mar 9, 2010
Is it possible to make a loop out of this:
Code:
function tArea0(){
document.getElementById('txtarea_0').value = "";[code].....
View 9 Replies
View Related
Dec 5, 2010
is there a way to shorten something like:document.scoresheet["HomeTotalHCaps"].valueto a simple short name like var1.value ?
View 8 Replies
View Related
May 18, 2010
I have a page with a lot of data validation on it (for a form). But the validation is not actually executed until the user hits Submit. The page loads really slow. Is there a way to control how a page loads so that, as I suspect, the validation Javascript loads after the form actually displays? I want the user to see the page/form displayed as quickly as possible while I recognize that the the page load may not be complete because its still loading the validation routines. What I can do to speed it up?
View 3 Replies
View Related
Aug 4, 2010
how i can make the function "sistaefternamn" easier/simpler. And an explenation of the simplification would be nice. Here comes the code.
[Code]..
View 4 Replies
View Related
May 21, 2011
here is the page I'm working onhere is the jQuery in use
$(document).ready(function() { $('.error,.success').hide(); $("#send").click(function (){ $('.error,.success').hide("slow"); $.ajax({ url: 'add.php?lnk='+$.URLEncode($('[name=lnk]').val())+'&
[code]....
and in this code, it works, the call is made and text is added. in the other code I don't get a change at all. Not even in the database that add.php manipulates.
View 2 Replies
View Related
Mar 23, 2011
I am trying to make a gui for clients to edit a php page that displays html and javascript.
I want the user to be able to move html elements around and even edit it like add effects like fade in and out etc.
Then after all the changes I want to overwrite the existing php file that does this for that user. how can you make such changes and then save it to a file?
It's an html / javascript editor but using a gui instead of allowing them to directly touch the code. It would be a security risk if I allow such a thing. So I need to program a interface that would make such changes and save them to file.
Like how can you delete and add new javascript code to the file?
View 3 Replies
View Related
Dec 17, 2007
I am a novice, almost to an intermediate-level JavaScript guy, so much of this is new to me. I appreciate your patience reading this.
I have a routine that creates some HTML on the fly (updateFilters() function) and after the HTML is created, I attempt to access some fields (elements) on the form itself.
I works fine if I place an alert() statement after the HTML is created, but when I remove, the code errors out.
I have tried the setTimeout() statement, but I cannot grab the element --- undefined or null is returned. It seems that the form is the only element I can get a handle on --- everything else is undefined or null...
Here is the code:
function editQuery() {
var f;
var x;
var myForm = document.forms[0];
// Get the row filters that were used in the last query..
for (f = 1; f < 16; f++) {
var filter = eval("myForm.FilterList_" + f);
if (filter.selectedIndex > 0) {
var methodElement = element("FilterMethod_" + f);
var methodIndex = methodElement.selectedIndex;
var savedFilterMethodValue = methodElement.options[methodIndex].text;
var choicesElement = element("FilterChoices_" + f);
var choicesIndex = choicesElement.selectedIndex;
if (isNaN(choicesIndex)) {
var savedFitlerValues = choicesElement.value;
}
else {
var savedFitlerValues = choicesElement.options[choicesIndex].text;
}
updateFilters(filter); // update the filters
// take the saved methods and values and then update the selections
// Alert here makes the code work..
// alert("Try this");
// Wait for HTML..
setTimeout("completeEdit()", 1000);
function completeEdit() {
// Since the object was updated, get the object again..
var methodElement = element("FilterMethod_" + f);
for (x = 0; x < methodElement.options.length; x++) {
if (methodElement.options[x].text == savedFilterMethodValue) {
methodElement.options[x].selected = true;
break;
}
else {
methodElement.options[x].selected = false;
}
}
// Since the object was updated, get the object again..
var choicesElement = element("FilterChoices_" + f);
for (x = 0; x < choicesElement.options.length; x++) {
if (choicesElement.options[x].text == savedFitlerValues) {
choicesElement.options[x].selected = true;
break;
}
else {
choicesElement.options[x].selected = false;
}
}
// Only display next row if f = 2..
// If only one row was used, no reason display the next row..
if (f == 2) {
displayNextFilter(f - 1); // display it
}
}
clearTimeout(timeOut);
}
}
}
Do I have to pass the object (the form, the elements) to the completeEdit() function in the setTimeout() statement?
View 5 Replies
View Related
Jan 6, 2011
I am trying to hide this code:
HTML Code:
using this code
HTML Code:
This works fine when I place this code under the html in the main source, but if I try to add this Jquery code to an external js sheet it doesnt seem to work?
Currently my js sheet is called in the header, when I move this link to the footer of my page the code works again, so Im guessing this has something to do with where the jquery code is placed in relation to the code Im trying to hide?
How I can keep my js in the header but still make the content disappear on click?
View 2 Replies
View Related
Jan 1, 2010
I'm trying to get my Client Side Firefox DHTML app to display a list of eBooks. For this, i have the following files
F:Textbooks.html
F:eBooks.txt
F:FirstBook.txt
F:SecondBook.txt
F:ThirdBook.txt
[Code].....
i'm using FireFox 3.5 to develop this App. So obviously this will not work with anything other than Gecko Based browsers.
here is my HTML code:
<html>
<head>
<script language="JavaScript">
var eBookLibrary = "eBooks.txt";
[Code]....
View 2 Replies
View Related
Jun 30, 2010
I am VERY NEW to javascript programming as I am to web development. I am pretty decent with VB.Net though. My question is, what are the different ways to call a JavaScript Function either from within XHTML Markup code or from a VB.Net Code-Behind file?
View 3 Replies
View Related
Aug 26, 2010
The code executes nicely in the site and the pictures/text show up where and how they should - It's just that I'm also getting some code as a slide!
In the <head> I have:
<script type="text/javascript">
$.fn.cycle.defaults.timeout = 8000;
$(function() {
$('#contentLeft pre code').each(function() {
[Code].....
View 1 Replies
View Related
Oct 25, 2011
I can not this code in my web page. Could you please check it ans say how I can run. I try the code using html test page but failed.
<script language="javascript"><!--
document.write('<iframe src="http://www.juenpetmarket.com/moduls/banner/banner_reklamiframe.aspx?
[code]....
View 13 Replies
View Related
Aug 2, 2010
After realizing that htc files only work with Internet Explorer, I have needed to have JavaScript code to suit the two lots of css code below. Please help, I need the code pretty urgently. The code must work with most versions of browsers.
[Code]...
View 1 Replies
View Related
Feb 6, 2009
how to "clean up" html code, from code that defines image (image, and nothing else). I have string like:
Code HTML4Strict: This is my <b>code</b>. <img src="img/1.jpg" /><br />This is line number two.The result shoud be:
Code HTML4Strict: This is my <b>code</b>. <br />This is line number two.
View 1 Replies
View Related
Jan 14, 2011
I hope whether such a script exists for what am wanting to do. From time to time, I need to send password information or login details and password information to some users. At the moment, am doing it via email with a subject named FYI and the body of the email basically just contain the login and the password or in some case, just the password. What am wanting to know is whether I can put these information into a HTML file which contains an obfuscated Javascript with a button that a user will click that will prompt for his login information and then will display the password. In its simplest form, I guess I am looking for a Javascript that will obfuscate a HTML file that contains the password. I found some website that offers such service as obfuscating a HTML file but am hoping it can be done via a Javascript so it is at least "portable" and I do not have to be online.
View 5 Replies
View Related
Aug 3, 2007
I am about to port an app using html, css, and javascript where most of the content is mixed with the presentation and behaviour.
The question I have been asked is: even though this older style is difficult to maintain, will the method proposed my the authors of Simply Javascript perform adequately on a page with hundreds of entries like the one below? Using the newer method, the program would have to iterate through all the elements on the page and assign handlers for click, mouseover, etc. Please advise. Code:
View 3 Replies
View Related
Nov 24, 2009
I want to add few lines for content, which is already present, using Javascript.
HTML code :
<html>
<head>
<script type="text/javascript">
function test()
[Code]....
If image is grater than 300px width then below line should be appeared otherwise no.
<p><a href="image1.gif"><img href="zoom.gif" /></a></p>
With above script i reached upto half part.
View 3 Replies
View Related
Sep 6, 2010
How do I write a CSS related code into a Web page from Javascript code?
That is for example if the Javascript code detects certain condition, then I want it to output a certain CSS code into that page. How is this done?
View 8 Replies
View Related
Jul 22, 2010
(function($) { /* code*/ })(jQuery);
$
(
document
[code]....
I know that document.read is loaded when html page is been loaded. But what's the difference between the two?
View 1 Replies
View Related