Troy III 272 Posting Pro

hi i would like to change just part of my code to change the color of my answer to my maths game see the code

document.write("<br>3+2 = " + answer1 + " is incorrect - the correct answer is 5");

see where it says the answer is 5 i would like to change it to red but cant find how to do it

thanks

document.write(
      "<br>3+2 = "+answer1+" is incorrect! - "+("The correct answer is 5.").fontcolor('red'));
Troy III 272 Posting Pro

Well...
It's Authorial, -that's most probably the sole reason! :')

it's shorter than any jQuery or whatever -But, it's a Gen5 and will not work on Gen4 browsers! :( so for backward compatibility use, one would need a step backward syntax:

thisDay=
/*b.b. Troy III p.a.e*/{
    Date: function(){return new Date().toLocaleDateString()},
    Time: function(){return new Date().toLocaleTimeString()}
   }

//and call:
 
    thisDay.Date();
    thisDay.Time();
Troy III 272 Posting Pro
thisDay=
/*b.b. Troy III p.a.e*/{
    get Date(){return new Date().toLocaleDateString()},
    get Time(){return new Date().toLocaleTimeString()}
   }


thisDay.Date  >> "Thursday, March 08, 2012"
thisDay.Time  >> "09:49:38" or "9:49:38 AM" (IE) //will depend on a browser!
Troy III 272 Posting Pro

What do you mean by: form.elements.value = input; (me confused!?!) or, which element exactly?

And you won't need this: "grade = Math.round((grade * 0.2));" unless you are interested to return F on all inputs from 100 down to 0, (at least not with the route taken).

Anyway, you can try this :
(it should work if I understood the task correctly; and for a better user experience you might want to split your function in two )

function calcGrade() {
                var form = document.getElementById("form");
                var finalGrade = document.getElementById("final-grade");
                var field = form.elements['test1'];     
		var input = field.value, grade, max = 100, min = 0;

		if(input = parseInt(input, 10)){
			field.value = 
			grade = input > max ? grade = max : 
				input < min ? grade = min : 
				input;
			finalGrade.value =
				(grade < 60) ? "F" :
				(grade < 70) ? "D" :
				(grade < 80) ? "C" :
				(grade < 90) ? "B" :
				(grade <100) ? "A" : "!";
	            }
	    }
Troy III 272 Posting Pro

have you tried to spell the "lentgh" correctly?

Troy III 272 Posting Pro

Troy, the fiddle was totally contrived just to demonstrate that e.b could be fooled.

As I put the fiddle together, I wondered if e.b could be initialised as a namespace (ie. a native javascript object), in which you could store one value per CSS property.

It will look something like this:

function(e,p,v){
        if(!e.b) { e.b = {}; }
        e[p]==v ? e[p]=e.b[p] : (e.b[p]=e[p],e[p]=v);
    };

I've not tested this and it may not work because element.style.b = {} is probably illegal. But you should be able to work with a property of the element itself rather than element.style . With HTML5, you could use a "data-" property.

If this could be made to work, then you would have the means to toggle as many CSS properties as you want, independently.

Airshow

Of course, introducing a relay-object will allow more wires to be added to the switch.

decriptive form:

toggleXprop=
	function(owner, property, value) {
		owner.mneme||(owner.mneme={});
		owner[property]==value?
		owner[property] = owner.mneme[property]:
		(owner.mneme[property]=owner[property], owner[property]=value);
	}

lib. ver.:

toggleXprop=
	function(o,p,v){
		o.m||(o.m={});
		o[p]==v?o[p]=o.m[p]:(o.m[p]=o[p],o[p]=v);
	}

*Interestingly - we came up with exactly the same line of code in the main.
Anyway, this is a/the second grade function..., and only a half way there. Practice will reveal the third and final demand for completion.

But I still don't understand why would you use toggle for a hover effect?!

Troy III 272 Posting Pro

coming back from fiddle...
I notice that you've been trying to use the toggle as a hover utility also. But there's a problem with the approach, besides using the wrong tool for the job you have a three-state hover subject.
I haven't seen a three-state hover element either, a hover element has its initial and hovered property. There's no purpose in having an initial black element which turns blue on hover-in but red on hover-out and stays that way.
So to make it simple, although the spartan toggle was not meant to be used on sub-properties even though the example given is demonstrating its limits and doing exactly that, and especially not as hover utility, if properly applied it can be used to some extent as a 'normal' hover two-state utility too.

I remember the headache with hover functions in their debut times, !the hover default property needs to be set on style element in order to work.

/*
csss
#toggler{color:#09f}
for html
<div id="toggler">Script call for toggler</div>​
*/
toggleProp=
    /*b.b Troy III p.a.e*/
    function(e,p,v){
        e[p]==v ? e[p]=e.b : (e.b=e[p],e[p]=v);
    };

	var t = document.getElementById('toggler');
	t.setAttribute('onclick', 'toggleProp(this.style, "backgroundColor", "red")');
	t.setAttribute('onmouseover', 'toggleProp(this.style, "color", "green")');  
	t.setAttribute('onmouseout',  'toggleProp(this.style, "color", "green")');

Having a toggler at hand, brings up the idea of an event named "onhover" so that the redundant code like:
t.setAttribute('onmouseover', 'toggleProp(this.style, "color", "green")'); t.setAttribute('onmouseout', 'toggleProp(this.style, "color", "green")')
could be merged into a single line expression as in:
t.setAttribute('onhover', 'toggleProp(this.style, "color", "green")');

Dual purpose …

Troy III 272 Posting Pro

[selector] { position : fixed; ... }

Troy III 272 Posting Pro

good, now see what's being returned by:alert(document.getElementById(v))

Troy III 272 Posting Pro

Troy,

Reuse of e.b can cause cross-talk with multiple uses on the same element.

Try this fiddle.

Airshow

I should have mentioned that the "spartan toggle" is a single purpose switch.

A definition of a toggle is a two-state util (button) with a single (hardwired) purpose.
A two-state dedicated single-purpose util.

Switch: [purpose] // purpose = [power]
State: ON/FF

Once dedicated to [power] it gets hardwired to becoming an exclusive two-state power switch. Shouldn't be able to use the same button to switch audio[on:off] with it, and it cannot have more than two states.

Therefore if the switch purpose is a given it will become a color-switcher explicit; The color becomes the purpose of the switch. Where the off status is not a new mode, the Off mode is simply off, where off is an existing/default/unaffected state of the thing.
This is why you should be able to switch between modes, but not between purposes of the same element; [it can be used as a weak security feature too; meaning, the external script will not be able to modify the purpose of the switch with ease].

Troy III 272 Posting Pro

Will work on latest:Chrome Safari Firefox Opera and all versions of IE.
*(client notifications are for demonstration purposes only, and subject to designer decisions and modifications )

Can be used for size and mime-type restrictions.

When mime-type is not an issue, accepting any kind of image format can be done usnig "image" as a function argument.
Multiple mime-types allowed should be separated with the following syntax: "gif|jpeg|png" etc. [see the demo].
Numeric value signifies the maximum size in kilobytes.

Benefits: your client doesn't have to wait until the image uploads on the server just to see that his file is a byte or two bigger than acceptable or of a wrong image type. Reduces wasted bandwidth on wrong content tests and unnecessary server load.
No further scripting required for submit action denial when wrong type/size detected.

diafol commented: Only just come across this. Wow. Very very nice. Thanks Troy. +15
cereal commented: nice! +13
Troy III 272 Posting Pro

What is the value of the v pointer?
Try alert(document.getElementById(v)) before your if conditional and see whats being returned first.

Troy III 272 Posting Pro

hai everybody am using following code to preview the image before uploading it. but am unable to display the image please help me.

<SCRIPT type="text/javascript">

function preview(what){
	document.getElementById("previewField").src=what.value;
}
</SCRIPT>


	<INPUT type="file" id="picField" onchange="preview(this)">
	<IMG id="previewField" alt="Preview">

thank you.

Image preview before upload, is possible (up until now) only on Explorer UAs.

Troy III 272 Posting Pro
/*the ø stands for document.getElementById*/
function conwidth(){
var a=document.getElementsByClassName('dropdown');
var e=[];
for(i=0;i<=a.length;i++){
	if(a[i].innerHTML.length>28){
/*Safari Error (only if I bypass the setwid(j,k)command):
TypeError: 'undefined' is not an object (evaluating 'a[i].innerHTML')*/
		e.push(a[i].innerHTML);
		var j=ø(a[i].parentNode.id).parentNode.id;
		var k=200+8*(a[i].innerHTML.length-28);
		setwid(j,k);
	}
}
}
function setwid(b,c){
var dr=document.getElementsByClassName('dropdown');var st=document.getElementsByClassName('strich');var a=function(a){return ø(a.parentNode.id).parentNode.id;};
/*Safari Error: TypeError: 'undefined' is not an object (evaluating 'a.parebtNode')*/
for(i=0;i<=dr.length;i++){if(a(dr[i])==b){console.log('width');
dr[i].style.width=c+21+"px";}ø(b).style.width=c+"px";}
/*I get 14 width console.logs, but 0 strich!
but if i change their places i get 4 strich and 0 width*/
for(i=0;i<=st.length;i++){if(a(st[i])==b){console.log('strich');st[i].style.width=c+40+"px";}}
}

Could someone please explain me those errors and what I have to correct?

The javascript error is caused by your ø sign.

You need to make sure that ø symbol is a part of the language specified in the document - and javascript is depending on browser implementation possible to ignore it, therefore misinterpret it, -why not use id(...) instead of ø ?

Troy III 272 Posting Pro

Hi all,

I'm using scrollintoview to scroll to the element but it's very quick, do you know anything like this but smooth?

That's not because it is quick. The 'scrollIntoView' method doesn't actually scroll. It only makes the target jump strait into view.

Troy III 272 Posting Pro

Now it's a literal JS object.
Convert it with JSON parser and it's a tree.

Although you are not clear I couldn't understand what you were trying to do there

Troy III 272 Posting Pro

Many people are searching for this code, and not all codes are working for them :)
So, this is a bit easyer, ussualy a .js and/or .css file are required, but this one is simple!

STEP 1
Paste this into your page header:

<script type="text/javascript"><!-- 
function setFirstChildImgDisplay(el,vis) {
  if(!el || !el.getElementsByTagName) return;
  el.getElementsByTagName('img')[0].style.display=vis;
}
// -->
</script>

STEP 2
Paste this as a page content where you want it to appear:

<div onmouseover="setFirstChildImgDisplay(this,'block')" 
onmouseout="setFirstChildImgDisplay(this,'none')">Wahoooooo some Text yipeeeee
<img src="YOURIMAGEHERE.jpg" alt="short description of image"
style="display:none;margin-top:1em;"></div>

Don't forget to replace "YOURIMAGEHERE.jpg" to your image!
Sorry for my language, i'm a freaking Romanian!

So, what does it do, Milutz94?

Troy III 272 Posting Pro

I want to check the image size in JavaScript.. for example if image size is more than 500kb and other format instead of jpg.. it should not get uploaded.. i want to check these validation before form submit..

thanks in advance..

waiting for positive ans.

Regards

This will do your thing on all versions of Explorer.

<input type=file id=fileUp onchange="getImg()">
<img id=imgProbe src="" style="width:100px; display:block">
<script>
getImg=function(){
	imgProbe.src=fileUp.value;
	imgProbe.onload=function(){
		(imgProbe.fileSize/1024)>500?
		alert("500KB Exceeded!"):imgProbe.mimeType.match(/jpeg/i)?
		1:alert("JPG Required!")
		}
	}
Troy III 272 Posting Pro

This thing is Browser Implementation Dependent, so you'll need to hunt after specific browser solutions and if.

Troy III 272 Posting Pro

you've introduced some new kind of error there. File Protocol not specified{?}

But it doesn't matter, in case you are planning to publish it on internet it will play perfectly with relative paths anyway.

Troy III 272 Posting Pro

Try with absolute addresses of file sources instead of relative ones you might be using right now.

Troy III 272 Posting Pro

remove "controls" statements.
Put "autoplay" instead.

Troy III 272 Posting Pro

uninstall the plugin asap or better more try a restore point (but the exact one if it is created) also,
than try this code:

<audio controls>
  <source src="sound_5.ogg" type="audio/ogg"><!--firefox-->
  <source src="sound_5.mp3" type="audio/mpeg">
  <img dynsrc="sound_5.mp3" height=30 width=120 controls>
</audio>
Troy III 272 Posting Pro

The thing you are getting there is the text content of the link element - it seems{?}
and it is a lot easier to strip correctly.
And, it is valid and usable for as long as the link inner-text values are correct as well.
In that case a simple line of code will do your thing:

lnk = document.links['linkId'].innerHTML; //the following is, sport.
alert(lnk);  // >> "Home"
delete lnk; //[*]as soon as your'e done using it.

* because undeclared variables are erasable: meaning "green"; "biodegradable", environmentally friendly and pollution free.

Troy III 272 Posting Pro

my Math.average method may give you a hint on this...
snip is at:
http://www.daniweb.com/forums/attachment.php?attachmentid=6760&d=1216985919
discussion at
http://www.daniweb.com/web-development/javascript-dhtml-ajax/threads/136037/655952#post655952

A function written this way is self-adjustable to dyna-length of arguments given. This approach may solve your problem.

Troy III 272 Posting Pro

how complicated is the fn function?

Troy III 272 Posting Pro

Like:

fn(p[0])
fn(p[0], p[1])
fn(p[0], p[1], p[2])...


not:

fn(p[0])
fn(p[1])
fn(p[2])...

well, conventionally -that's not doable.
you'll need to write your function on the fly

Troy III 272 Posting Pro
var p = "one, two, three".split(',')
;for(i in p)fn(p[i]);
Troy III 272 Posting Pro

of course there is, what part of it do you need exactly?

Troy III 272 Posting Pro

In an XSLT file, I am calling a function to a javascript file (.ascx) and trying to pass parameters. One parameter is a Date() object. The only way I've found to successfully pass it is to pass it as a string.

Here's the code from the XSLT file.

<script>
      grouping("<xsl:value-of select ="Date1"/>", <xsl:value-of select ="ID"/>);
    </script>

Here's my function in Javascript.

function grouping(date, num) 
{
     // Date is now a string instead of a Date() object
}

What I want to do is keep the date object a date object and not a string. Anyone know how to do this? Otherwise, I'll have to parse the string and make a new Date out of the substrings.

Use Date function instead of a Date return Date() .

Troy III 272 Posting Pro

use javascript to grab the "ondrop" event; The "event object" keeps x,y coordinate values updated at all times, assign to variables like:

var x = ["event object"].clientX;
var y = ["event object"].clientY;

and use your ready handler to post them by referencing x,y variables.

Troy III 272 Posting Pro

Its a button I have on the page. Here is a clearer picture.

<head>
<script type="text/javascript">

window.onload = function(){
	easy();	
}

function easy(){
var ids = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,
			   51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81]
	var items = [3,0,6,5,0,0,0,9,0,2,0,0,4,0,0,8,5,1,1,0,0,7,8,0,0,6,0,0,0,9,3,6,8,5,0,0,6,2,8,0,0,0,3,4,9,0,0,5,9,2,4,1,0,0,0,4,0,0,9,7,0,0,2,8,6,				3,0,0,1,0,0,5,0,7,0,0,0,3,4,0,8];
	
	var ans = [3,8,6,5,1,2,7,9,4,2,9,7,4,3,6,8,5,1,1,5,4,7,8,9,2,6,3,4,1,9,3,6,8,5,2,7,6,2,8,1,7,5,3,4,9,7,3,5,9,2,4,1,8,6,5,4,1,8,9,7,6,3,2,8,6,3,2,4,1,9,7,5,9,7,2,6,5,3,4,1,8];
	
	var x = 0
	for (var i = 0; i < items.length; i++) {
	var item = items[i];
	var id = ids[i];		
	var element = document.getElementById(id).innerHTML = item;
	
	if (item === 0){
		document.getElementById(id).innerHTML="";
		document.getElementById(id).contentEditable = "true";
		document.getElementById(id).style.backgroundColor = "yellow";
	}
	function check(){
			for (var i = 0; i < items.length; i++) {
			var id = ids[i];
			var answ = ans[i];
			
			if(document.getElementById(id).textContent!= answ){
				document.getElementById(id).style.backgroundColor = "red";
			}
		}
		
		}//end of check
	
	}// end of easy
	
	
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link rel="stylesheet" href="tablestyle.css" type="text/css" />
</head>

<body>
<table id="main" width="50%">
  <tr>
    <td><div id="1"></div></td>
    <td><div id="2"></div></td>
    <td><div id="3"></div></td>
    <td><div id="4"></div></td>
    <td><div id="5"></div></td>
    <td ><div id="6"></div></td>
    <td><div id="7"></div></td>
    <td><div id="8"></div></td>
    <td><div id="9"></div></td>
  </tr>
  <tr>
    <td><div id="10"></div></td>
    <td><div id="11"></div></td>
    <td ><div id="12"></div></td>
    <td><div id="13"></div></td>
    <td><div id="14"></div></td>
    <td ><div id="15"></div></td>
    <td><div id="16"></div></td>
    <td><div id="17"></div></td>
    <td><div id="18"></div></td>
  </tr>
  <tr>
    <td ><div id="19"></div></td>
    <td ><div id="20"></div></td>
    <td ><div id="21"></div></td>
    <td ><div id="22"></div></td>
    <td ><div id="23"></div></td>
    <td ><div id="24"></div></td>
    <td ><div id="25"></div></td>
    <td ><div id="26"></div></td>
    <td ><div id="27"></div></td>
  </tr>
  <tr>
    <td><div id="28"></div></td>
    <td><div id="29"></div></td>
    <td ><div id="30"></div></td>
    <td><div id="31"></div></td>
    <td><div id="32"></div></td>
    <td ><div id="33"></div></td>
    <td><div id="34"></div></td>
    <td><div id="35"></div></td>
    <td><div id="36"></div></td>
  </tr>
  <tr>
    <td><div id="37"></div></td>
    <td><div id="38"></div></td>
    <td ><div id="39"></div></td>
    <td><div id="40"></div></td>
    <td><div id="41"></div></td>
    <td ><div id="42"></div></td>
    <td><div id="43"></div></td>
    <td><div id="44"></div></td>
    <td><div id="45"></div></td>
  </tr>
  <tr>
    <td ><div id="46"></div></td> …
Troy III 272 Posting Pro

who's calling the check function?

Troy III 272 Posting Pro

Unless you create a snapshot image of every page of interest to be displayed on hovering a link to it, there would be no benefit in doing so, because every other mean would require an actual download of the target source before you get it displayed on whatever you may have decided to display it onto.

But I'm pretty sure you may be able find scripts that generate thumbnail images already available on our wast www.

Troy III 272 Posting Pro

...but perhaps you need an explanation, for why is it happening -so you'll know it before it happens in the future. No html element will ever contain other data-type except a text, which when returned is of type string. therefore a returned 5 is not a number, its a literal, which perhaps when read by human who understands cursive numbers will know it as a literal representation of a number whose explicit value is 5.

To cut it short, with this thing in mind when a retrieved value is supposed to be passed as a numerical value from a textual source you can omit the parseInt function same as you would the Number constructor [which is more semantic and true to its nature] by forcing it with a short and single sign operator as in the following line of code:

var x = +xmlDoc.getElementsByTagName("x")[0].childNodes[0].nodeValue;

x= + yourlongargument; will immediately force a proper duck-type conversion of a given number literal so you wont be needing a parseInt(verylongargument) or Number(equallylongargument);

Note: the +arg will successfully convert "5"; " 5"; "5 " or " 5 " to Number, but not "5px" and alike.

Troy III 272 Posting Pro

I know there are more accurate geolocation methods, but I want to have it transparent to the user rather than ask them to "allow".
I am using a very simple method and it works great on most of the computers I have tried, but on some such as my grandmothers laptop with IE7 I think and Windows XP, as well as a friends MAC, it did not work.
I figured that even if the location database came up empty, the else statement should fill in for New York, no?

What am I missing? thanks.

<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">// <![CDATA[
if (typeof(google.loader.ClientLocation.address.city) != null) {
  document.write(google.loader.ClientLocation.address.city);
} else {
  document.write("New York");
}
// ]]>
</script>

your conditional is wrong if (typeof(google.loader.ClientLocation.address.city) != null) { try it with:

if ( typeof( google.loader.ClientLocation.address.city ) ) {...

instead.

! Nope, this wont work either! You'll need my special exists() method instead.

Troy III 272 Posting Pro

Nicely done.
It's true, they are all flickering in FF. And my gpu fan went louder shortly after opening it with FF.
Possibly because the action is event-driven and the handler is being triggered at leas twice.

Troy III 272 Posting Pro

I know this is a basic question. I asked the same question a while ago, even then thinking it was a simple question. The answer I got seemed to be what I already know and was obvious.. however, when I tried it, it did not work, so I just worked around it for a while... But now the same question is coming up, and this method is still not working...

<p>Name : <input type="text" id="theName" name="theName" value=""></p>
<p><input type="button" name="btnGo" value="Go" onClick="goNow(document.getElementByID('theName').value)"></p>

that is what I currently have, and for some reason it is not working... am I doing something wrong, or why is it not working?

This is your code

<p>Name : <input type="text" id="theName" name="theName" value=""></p>
<p><input type="button" name="btnGo" value="Go" onClick="goNow(document.getElementByID('theName').value)"></p>

What's it supposed to do, because the code provided is absolutely unclear at this point. It doesn't unveil your aim nor what you are aiming to achieve with it
Let's first correct your spelling error on the method first:

<p>Name : <input type="text" id="theName" name="theName" value=""></p>
<p><input type="button" name="btnGo" value="Go" onClick="goNow(document.getElementById('theName').value)"></p>

Now, even if your "goNow" would happen to be the name of some well written function, it should return nothing since the value of your "theName" input is empty by default.
At this point, the "goNow()" [name of some presumed existing function] doesn't tell us much -not even after giving it some seriously deep dark thoughts.
We are after all ordinary coders; some are good, some are better, but in either case …

stbuchok commented: I'm starting to appreciate your humor +7
Troy III 272 Posting Pro

I know this is a basic question. I asked the same question a while ago, even then thinking it was a simple question. The answer I got seemed to be what I already know and was obvious.. however, when I tried it, it did not work, so I just worked around it for a while... But now the same question is coming up, and this method is still not working...

<p>Name : <input type="text" id="theName" name="theName" value=""></p>
<p><input type="button" name="btnGo" value="Go" onClick="goNow(document.getElementByID('theName').value)"></p>

that is what I currently have, and for some reason it is not working... am I doing something wrong, or why is it not working?

What's not working?!!

Troy III 272 Posting Pro

Question, if a persons name is 'Edward van der Sar', wouldn't it show on the card as 'EDWARD VAN DER SAR' just like 'JOHN P SMITH'?

It doesn't matter how will it show on the card itself - what matters is how will it be stored on the database. The case doesn't matter - it will be overridden one way or the other. All uppercase or all lowercase. Since human names are case insensitive by nature.
Yet the most common action is toUpperCase before storing. But that doesn't matter Because anytime you try to compare you will first uppercase them or at least match up with the "i" flag set. Therefore, once again before diving in further speculation:

var check = 
/*b.b Troy III p.a.e*/
function(name, userInput){
	var test = name.match(/\b[A-Za-z']+\b/g); 
	userInput.value = test.join(" ");
		for(x in test)if(test[x].match(/([a-z])\1{2}/))alert("Please check your spelling on: "+test[x]);
	};
<your input onkeyup="check(this.value, this)">

try this and tell us whats up, because I'm pretty sure that this is all you need prior to on before submit action.
------
sorry onkeyup is not the perfect choice here I overlooked the fact that I'm removing the trailing spaces first, try it with onbeforesubmit or utilize the function with a conditional keycode input to halt the check if it happens to be a spacebar use return

Troy III 272 Posting Pro

that's all irrelevant since legally names and words may contain double letters in one and in alternate case like Cc, cc, too, but not or never Ccc, or ccc+, so you don't need to check or reject doublets, but triplets. My secondary regexp will take care to eliminate triplets of user input, whereas the primary one will do more than 90% of all cleaning required.

Either way no matter what you add to this, the only thing you may achieve is to lessen input errors, -which in the end [as already pointed out on my previous posts] may, or may not match with existing valid card names. -You can however achieve to store names which (at least theoretically) may belong to real individuals with cards.

Have fun

Troy III 272 Posting Pro

Note that:
Names are and should be case insensitive, therefore: "john p smith" equals "John P Smith" wihich is equal to "jOHN p sMITH" since they all mark and point to same Person!
Meaning that you are wasting your attention on irrelevant things. Since this match should be case insensitive.

Second: No special chars exist on real personal names, therefore your regexp may and should discard all portions of names which may contain: "_Smith", "@Smith", "Sm1th" and similar. var name = " J0hn P ., Smith " should return an clean and only ["P", "Smith"] as the only valid part[s] of input in the list.

In this regard you can try the following code strategy:

var name = " J0hn P  .,   Smithtttttt ";
/*b.b Troy III p.a.e*/
var test = name.match(/\b[A-Za-z']+\b/g);

// '
// should return a list containing: ["P", "Smithtttttt"] only! 
// than you should immediately correct the input to: 

userInput.value = test.join(" ");

// displaying: P Smithtttttt
// so he/she can see that the unaccepted part was rejected 
// and continue without a break to: 

for(x in test)if(test[x].match(/([a-z])\1{2}/))alert("Please check your spelling on: "+test[x]);
// which will present your client with the alert message saying: 
"Please check your spelling on: Smithtttttt"

No need to bother with lower case upper case letters at all...

Troy III 272 Posting Pro

This will extract you a list of pure legal names including the "O'Brian" type, and fully strip them from any kind of white-space [leading, trailing, and in-between].

/*b.b Troy III p.a.e*/
name.match(/\b[A-Za-z']+\b/g)

Than you can use
a three letter mach to return errors on individual parts, since it is true that no real name can contain Aaa Bbb or Cccc

/[a-zA-Z].{2}/

And you can stop there.

The first regexp will discard any part of input that contains illegal characters that can not constitute a true name and get rid of extra white spaces.

The second one will enable you sequentially check for 3x letter repetitions, on individual parts of the input so that you can return errors with the value tested on n[0]; n[1]; n[2]...

Yet this doesn't guard you from someones input like: "Abvgr X Drmge" -although I can't bet you that there isn't a person with that kind of name living somewhere in this world.

But atop it all - John P Smith may happen to be a real and completely valid name of the user - but that doesn't mean that he also has a card on his name or that particular name for a fact. So at the end of the day... -The only valid check is checking against the bank of client names and see if they match with the input given.

Troy III 272 Posting Pro

what i acctual needed was that some one has to clickthe table content ie the link below "jimm" so as to make the "next" button clickable

<!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>
<style type="text/css">
</style>
</head>

<body>
<script>
	toggleProp=
	/*b.b Troy III p.a.e*/
	function(e,p,v){e[p]==v?e[p]=e.b:(e.b=e[p],e[p]=v)}
</script>
<form  autocomplete="off">
	<input type=checkbox onchange="toggleProp(document.forms[0].button,'disabled',0)">
	I accept<br> 
	<input type=button name="button" value=Next onclick="yourFunction()" disabled>
	continue<br><hr><hr><hr>

what i acctual needed was that some one has to clickthe table content ie the link below "jimm" so as to make the next button clickable 


<table border="0" width="100%" cellpadding="0">
<tr>
    <td valign="top"> 
<a href="#">jimm<a/>
<td/>
<tr/>
<table/>
<br>
<input type=button name="butto" value=Next>

    
</form>
</body>
</html>
<!doctype html>
<html>
<head>
<meta charset=utf-8>
<title>Untitled Document</title>
<style>
</style>
<script>
	toggleProp=
	/*b.b Troy III p.a.e*/
	function(e,p,v){e[p]==v?e[p]=e.b:(e.b=e[p],e[p]=v)}
</script>
</head>

<body>
what i acctual needed was that some one has to clickthe table content ie the link below "jimm" so as to make the next button 

clickable 

<table>
 <tr>
  <td><a href="javascript:toggleProp(document.forms[0].butto,'disabled',0)">jimm</a></td>
 </tr>
</table>
<br>
<form>
 <input type=button name=butto value=Next onclick="yourFunction()" disabled>
</form>
</body>
</html>
Troy III 272 Posting Pro

no it didn't and can't.
and of course you don't alert the unprocessed string if you really like to know what that expression does to it,but the processed one. ie
alert( n.split(' ').join('') )

Troy III 272 Posting Pro

Relax dude, nobody can write a program by hart in a single breath. You need to take it one step at the time, The solution from your link is quite complete -why don't you use that.

Troy III 272 Posting Pro

remove the join() part and try again.

n.split(' ').join(''); //get rid of extra white space;

-you are not getting rid of the white space, because there already isn't any. What you are doing there there is that you are taking the 'John P Smith' and converting it into a; [for your aim] an unusable 'JohnPSmith' string instead.

Troy III 272 Posting Pro

am having trouble with this small java-script problem

how can i make a link button clickable after an event lets say clicking a check-box or another button ...example when you want to install a software you see the next button but can not click it until you check the check-box of accepting terms and getme!!! pliz write me the sniplet,,,thanks

<form  autocomplete="off">
	<input type=checkbox onchange="toggleProp(document.forms[0].button,'disabled',0)">
	I accept<br> 
	<input type=button name="button" value=Next onclick="yourFunction()" disabled>
	continue
</form>
<script>
	toggleProp=
	/*b.b Troy III p.a.e*/
	function(e,p,v){e[p]==v?e[p]=e.b:(e.b=e[p],e[p]=v)}
</script>

to make sure it keeps in sync on page refresh bug introduced by "modern browser" idiocy,
-add this function to the script:

onload=function(){document.forms[0].reset()}
Troy III 272 Posting Pro

Your assumption is right. It is there...
The line:

delete p.innerText // >> true.

Undeletable property flag would also disable its write ability and as a consequence we would get a read-only innerText property.
The innerText (as other initial element properties) is inherited from the prototype: not owned by the element itself. (That's why the line 4 persistently returns "" which is found up the prototype chain instead of expected 'undefined') As soon as we assign something tho the innertext property of the element it gets created and overshadows the initial value existing higher on its prototype. That's why as soon as we delete it (line 3) the line 4 value will shine through again, which is by the way one of the most powerful principles in Live Script.

Aside all that, the "hasOwnProperty" method was introduced and (is by definition) designed and defined in a way that it would allow only owned properties of the current object to 'shine through' or be exposed to the code. Any behavior other than that, is a bug; a wrong implementation, or implementation error.
If needs to be said: it defeats the purpose and the reason of its existence.

Troy III 272 Posting Pro

Correct Troy, I meant .textContent .

And yep, agreed prop in obj is best. Good solution.

It's academic but out of interest, browsers differ their implementation of these properties.

  • Opera : oElement.hasOwnProperty('innerText') gives true
  • IE9 : oElement.hasOwnProperty('innerText') gives false

Both support .innerText , so it's a question of own vs. inherited - therefore unreliable to test .hasOwnProperty() .

Airshow

Well, that's odd. I never knew that Opera DOM elements don't inherit! Or do they?...
There's something odd going on there, and it needs to be tested before drawing any conclusion.

Probing something like:

var p = document.createElement("p")
p.innerText // > "" // correct!
delete p.innerText // > true
p.innerText // > ""  //intact!
/*should yield "undefined" if property was earned */

But it doesn't. Meaning that native properties of elements are indeed inherited from their corresponding prototypes, which on the other hand says that element hasOwnPrperty in Opera is browsing its constructor properties instead of its own.
The: delete p.innerText // which doesn't destroy the Type of its innerText property from "" to undefined, assures us that the property is indeed inherited. Which makes it clear that this behavior is Operas bug of its hasOwnPrperty implementation and should be reported.