Sagewire Logo

javascript programming RSS Feed

Recent Posts View Recent Posts | View Archived Posts

Message from John
Most recent post: 10/28/2007
4 authors and 4 replies.

Hello,

I was thinking of trying out JAVAScript and learn it on my own.

I had a few questions though.

Is it still popular with businesses today?

Is JAVAScript bad for search engine opt. (SEO)?

Any other help'd be appreciated.

I have tried som PHP stuff and now want to move on to something else. read more about Question on JAVAScript as a programming language


Message from The Natural Philosopher
Most recent post: 10/28/2007
8 authors and 30 replies.

Another extremely weird feature from iE6

I have a site, whose predominant colors are green background with white
writing.

There is a style sheet with many styles, of which all either specify a
green background, or do not specify any. Body defaults to green.

At the customer site, some <INPUT type="TEXT"> elements showed up with a
white background on one machine running IE6. I did not have a chance to
investigate further. Highlighting the white on white entered text showed
it was there, just invisible

Further madness occurred when on this machine a form containing about 10
of such inputs, that as far as I know were identical HTML, showed up
with some white and some green background.

My own test machine running AFAICT the same IE6 version doesn't display
this problem.

Her is a code snippet that gave some fields white, some green:-<TABLE width=90% border="0">
<TR><TD align="right">Name:</td><TD align="left"><INPUT type="text"
maxlength="32"name ="name" value="">
</td>

<TD align="right">Phone:</TD><TD align="left"><INPUT type="text" name=
"phone" maxlength="32" value="">
</td>
</TR><TR>
<TD align="right">Address 1:</td><TD align="left"><INPUT type="text"
name="address1" maxlength="30" value="" read more about Possibly OT. IE6 and background colors..


Message from McKirahan
Most recent post: 10/28/2007
2 authors and 2 replies.

Can someone show me the JAVAScript equivalent
to the following VBScript? Thanks in advance.

Randomize
For I = 0 to 15
intRnd = Int((16 * Rnd) + 1)
Next

Perhaps the follwoing is a start?

var Rnd = Math.floor(Math.random() * 16);
for (i=0; i<16; i++) {
// ?
} read more about JS equivalent of VBScript "Rnd"?


Message from dunerunner
Most recent post: 10/28/2007
2 authors and 4 replies.

We've a table within a div whose overflow-x is scroll. It is a long
table, so the width of the div is 800px, giving us a scrollbar at the
bottom. When users tab from cell to cell, the cells that contain
select elements that were out of the visible viewing area acquire the
focus, but they are still visually off the scrolling region. So, the
user has to manually move the scrollbar to bring the element into
view.

Is there a way we can manipulate the scrollbar (or whatever) to move
that entire element into view?Thanks,

Tim read more about Scrolling a div


Message from donpro-2003
Most recent post: 10/28/2007
3 authors and 6 replies.

Hi,

I have an session application where the user logs out via a simplt
logot link. The code to do this is:
<a id="logout" title="Log out" href="logout.php" onClick="return
confirm('Do you really want to log out?')">
Logout</a>

So if the user answers YES to the confim, logot.php is run and the
user is logged ot. If the user answers NO, they remain on the page.

I removed the onClick() and tried to use DOM but I find that with my
code, the user gets logged ot regardless of whether they choose YES or
NO so obviosly, my code is incomplete. I present it below, if anyon
can help, I wodl appreiciate it.

HTML
-------
<a id="logout" title="Log out" href="logout.php">Logout</a>

JAVAScript
========
function addEvent(elm, evType, fn, useCapture) {
if (elm.addEventListener) {
elm.addEventListener(evType, fn, useCapture);
return true;
} else if (elm.attachEvent) {
var r = elm.attachEvent('on' + evType, fn);
return r;
} else {
elm['on' + evType] = fn;
}
}

function handleClick(e) {
return confirm('Do you really want to log out?');
}

function addListeners() {
if (!document.getElementById) {
return;
}

var logout_link = document.getElementById('logout');
addEvent(logout_link, 'click', handleClick, false);
}

addEvent(window, 'load', addListeners, false); read more about How to flag onclick() and confirm() using DOM


Message from Brian Adkins
Most recent post: 10/28/2007
7 authors and 67 replies.

I'd appreciate recommendations for JAVAScript code that implements
drop-down, hierarchical menus. Are there high quality libraries for
this, or is it more typical for people to roll their own?

My preference is for open source code, but royalty-free commercial
code'd be acceptable as well.

Ideally, the code'd:
* Allow configuring horizontal or vertical menus
* Allow configuring the delay for closing the menu after mousing out
of the menu
* Provide a mechanism for playing well with existing code and other
libraries
* Be well designed & documented
* Be highly portable among browsers in common use
* Allow styling via css

Thanks,
Brian Adkins read more about Recommendations for JAVAScript drop-down menu code


Message from Rob
Most recent post: 10/28/2007
7 authors and 14 replies.

I want to implement a in-memory row selection function. Specifically,
given a table

Name Zip Phone
Tony 98034 127xxxxx
Mike 10023 271xxxx
Jame 10023 253xxxx

and a text box, I want the table automatically show relevant rows and
hide others. Say I type 10023,
only row 2&3 should be shown. Any existing package for doing this? read more about In memory row selection


Message from donpro
Most recent post: 10/28/2007
4 authors and 5 replies.

Hi,

I have created a table where the header columns link to an AJAX function
which calls a PHP file and returns content - the purpose is to sort
the table on the heading.

The code snippet is:
<th scope="col"><a href="JAVAscript:;" onclick="loadBookingContent('<?
php echo $SERVERPAGE_URL . SORT_BY_BOOKING; ?>
','innerhbl')">Booking</
a>
</th>

<th scope="col"><a href="JAVAscript:;" onclick="loadBookingContent('<?
php echo $SERVERPAGE_URL . SORT_BY_VESSEL; ?>
','innerhbl')">Vessel</
a>
</th>

<th scope="col"><a href="JAVAscript:;" onclick="loadBookingContent('<?
php echo $SERVERPAGE_URL . SORT_BY_CUTOFF; ?>
','innerhbl')">Cutoff</
a>
</th>The $SERVERPAGE_URL variable also contains one parameter, a session ID

I'd like to convert this to DOM and store the code in an external
JS file thereby separating the JAVAScript code from the HTML.
However, I need to pass the first content of the loadBookingContent()
function but my PHP code does not work in an external JS file.

I'm relatively new at DOM but there must be a way.

Thanks,
Don read more about How do I convert old onclick() code to DOM if a PHP variable is involved?


Message from Richard Hijdra
Most recent post: 10/28/2007
6 authors and 20 replies.

NG,

I got the following issue;

Would like to transfer multiple values from a fill-in form to a second
page using strings in the URL.

Have got it worked out for one value allready;

On page with form (using ASP)
this script; http://www.rhi.nl/temp/contact.txt (view source)

I use the following;

Response.Redirect("bedankttr.htm?"+Trouwdd.Value+"");

Of course I can edit this to
Response.Redirect("bedankttr.htm?"+Trouwdd.Value+""+Naam.Value+"");

But can not make it work on destination page to pull out the second value
on another place.

On destination page (for example
http://www.rhi.nl/contact/bedankttr.htm?01-01-2008)
I have putted in;
<script type="text/JAVAscript">
<!--
newVar=location.search;
document.write(newVar.substr(1));
//-->

</script>

How do I distill the second value from the string?

Richard read more about Passing MULTIPLE values using URL string


Message from Shocky
Most recent post: 10/28/2007
6 authors and 21 replies.

Hi there,

I am trying to detect whether my IE6 users have pressed both right and
left mouse buttons simultaneously in my JAVAscript code, by using:

if(event.button==3) {alert("Both right and left mouse buttons
pressed");}

I am calling the above code on mousedown or mouseup events.

But it doesn't seem to work. :,(

The if condition isn't satisfied even on pressing the left and right
buttons simultaneously.

Is there something that I am missing?

Best,
Shocky read more about Simultaneous pressing of left and right mouse buttons


Message from Jes
Most recent post: 10/28/2007
8 authors and 10 replies.

Dear all

I have a date field on a HTML form where the user is asked to key in
dd/mm/yyyy
However, when that is written to MySql it is either not accepted or
another value is tored in the database.

Is there any way to change value of this field back to yyyymmdd format
as accepted correctly in sql. ? The change should preferably be when
user click on submit.
Does anyone know of any code/function that does this ?

I'm using PHP and HTML

Thanks
Jesmond read more about Date field in DD/MM/YYY


Message from dan
Most recent post: 10/28/2007
3 authors and 6 replies.

Hi

I'm creating a very basic Ajax "Suggest" type script. I have the
server side OK, and the response gets back OK. I have had to use
responseText, as for some reason xmlResponse does not seem to work if
more than one <message> element is present. But that is not the point
of this post, so I'd better get to that.

Once I have the list of values that match the user's search term, I
display them as a list in a <div>. When the user clicks on one of the
list, that value is placed into the textfield.

Here are three ways I attempted this, but the only one that allows
anything other than the last element to accept any kind of focus is
the one that uses innerHTML for the entire thing.

Can anyone tell me why the other two do not work? They all display
pretty much the same, until you move the cursor over the list. The
last two automatically move the focus to the last item on the list. I
should add that I have only tested these in IE 6, and Firefox 2 (both
for Windows).

Any pointers with this very much appreciated.

Cheers

Dan

Assume all of the following are performed within a for loop

// This is the one that works
ss.innerHTML += "<div class='norm' onmouseover=
\"JAVAscript:this.className='over'\" onmouseout=
\"JAVAscript:this.className='norm'\" " +
"onclick='SetSearch(this.innerHTML)'>
" + text + "</div>";

// This does not work
var d = document.createElement('div');
ss.appendChild(d);
d.in read more about innerHTML works, but DOM does not - Please Help


Message from SaraLeePerson
Most recent post: 10/28/2007
7 authors and 11 replies.

Dear group,

I am seeking a easy to maintain and more importantly *working* way to
pre-fetch images, so the pages I develop load smoothly without seeing
the images kick in flicker as they usually do. Important - I need
this to work on Internet Explorer 6.0+ and FireFox.

I am presently using at the head of the page,

pic100= new Image;
pic100.src="./imageme.gif";

However, it does not seem to work on FireFox at all. I have tried
different combinations with the URL path, but I do not know what I am
doing wrong. Can someone please assist me with this boggle?

Thank you very much in advance for any assistance.:)

Best wishes, Sara. read more about Question, need expert help pre-loading images properly (IE + FireFox), thank you :)


Message from Melbfella
Most recent post: 10/28/2007
4 authors and 7 replies.

G'day all

I apologise in advance for the newbiness of this question, but the
answer has eluded me for 3 days now - hopefully one of you gurus out
there might be able to help .......

I have a page that dynamically draws checkboxes and am attempting to
use the following code to iterate through each text box, see if it's
checked - if checked, change a combo box to match the number typed in
a checkbox. Here's the code that calls the functions, and the
functions themselves......

**Code that fires the event
<input class="ctlstandard" type="text" name="txtSeats" id="txtSeats"
onblur="calculateCost();setOptionCombos();"/>
&nbsp;<font color="<
%=session("BrandTextColour")%>
">*</font></td>

<input type="checkbox"
onclick="showHideJumpPoints(this);calculateCost();" name="chkOption"
value="<%=rs("TourOptionID")%>
"/>**The functions
function calculateCost(){

var dblCost=0;
var lSeats=frmMain.txtSeats.value;
//alert('calc Cost');
if(isNaN(lSeats)){
document.all.txtSeats.focus;
alert('Please enter a number in the seats field');
}
dblCost=lSeats*frmMain.txtTourCost.value;

for (i=0;i<frmMain.chkOption.length;i++){
if (frmMain.chkOption[i].checked==true){
alert(frmMain.chkOption[i].value);
dblCost =dblCost +
(frmMain.cboTourOptionQty[i].value*parseInt(frmMain.txtOptionCost[i].value));
//alert('This option is checked');
//break //exist for loop, as target acquire read more about Iterating through checkboxes using JAVAScript


Message from newspost
Most recent post: 10/27/2007
4 authors and 4 replies.

I'm working on an application that requires a lot of internal data -
short texts, numbers, switches etc. At the moment the only way I have
of loading these is long lines of Array[1,2,3 etc]=The Data. In the VB
version I read data in from text files - is there a similar feature in
JAVAScript - or at least soem thing mroe flaxible than lines and lines
of assignments?

Marshal read more about best way to load arrays with large amounts of data?


Message from jamesallen74
Most recent post: 10/27/2007
11 authors and 27 replies.

I am a college student getting ready to take a JAVAscript class. From
what I hear it is pretty lame and I want to learn more about
JAVAscript than what the class offers. While I am taking the class, I
thought it'd be a good time to take my studies to the next level
and learn more things about it on my own.

If you had the chance to design and teach a class on beginner & mid-
level JAVAscript, what'd you cover? What do you think is
important for people to know about coding in JAVAscript?

thanks,
James read more about Taking a class that may suck?


Message from dhtmlkitchen
Most recent post: 10/27/2007
4 authors and 23 replies.

JSON
We all know what it is.

In ECMAScript 4, there's a JSON proposal:

Object.prototype.toJSONString
String.prototype.parseJSONThe current proposal, String.prototype.parseJSON, returns an object.
This is very poor design. It's worse than Date.parse(s), which returns
a Number (not a Date).

The current proposal, Object.prototype.toJSONString, complicates
objects with responsibility that they shouldn't necessarily have. It
will be easy to misuse. It'll conflate Object.prototype with
implementation details possibly leaking into places they should not.
Instead of keeping reduced access, it maximizes access. It doesn't
allow the functionality to be tested and debugged independently.

If these features go in the language, implementations and library
authors will be required to handle this method for all objects, of any
type, forever. The change will be permanent and unretractable.

This feature isn't critical; it can be added at any time. The flip
side to that is that once added, it cannot be removed. ever.
Alternatives

1. A built in JSON object

A built in JSON object'd keep the JSON serialization/parsing
independent. It'll be easy to learn, easy to extend, easy to read
and maintain code that uses it, and it'll fulfill the requirements.
It won't complicate Object.prototype.

JSON.parseFromString( s );
JSON.toJSONString( jsonObject, pretty ); 2. A JSON Interface

A JSON interface can be implemented to allow a cl read more about Current JSON Proposal in ES4


HAI
Message from kailingiri.m
Most recent post: 10/27/2007
3 authors and 3 replies.

HAI AL FIRST TIME read more about HAI


Message from jessica6_2000
Most recent post: 10/27/2007
4 authors and 7 replies.

I have a page where I need to display the unix time (seconds) upon
page load. I have found many complex examples that auto update, count
live, etc., but I need to just display the time at the time of page
load. I think it has something to do with getTime, showDate, or maybe
loadTime, but I can not quite seem to get the syntax.
Could someone provide the exact syntax and usage within the html to
make this work?

Thanks! read more about getting date/time from JAVAscript


Message from benkasminbullock
Most recent post: 10/27/2007
3 authors and 5 replies.

I have a script which adds rows to an HTML table. However, the script
functions only for Firefox and not for Internet Explorer. Here is a
test case which works on Firefox 2.0.0.8 but doesn't work on Internet
Explorer 6.0.

Can anyone explain why this doesn't work, and is there a way to make
it work with Internet Explorer?

What bothers me is that modifying the script slightly to change the
table to a <ul> and the <tr> to a <li> does work with Internet
Explorer.

Thanks for any help.

%%%%%%%%%%%%%%% start of example

<html>
<head>
<script>
function add_a_row()
{
alert ("Add a row");
var cell = document.createElement("td");
cell.appendChild(document.createTextNode("Second"));
var row = document.createElement("tr");
row.appendChild(cell);
var mytable = document.getElementById("mytable");
mytable.appendChild(row);
}
</script>
<style>
table { border-style: outset; border-width: 3; }
td { border-style: inset; border-width: 3; font-size: 50; }
</style>
</head>
<body>
<table id="mytable">
<tr><td>First</td></tr>
</table>
<form>
<input type="button"
onclick="add_a_row()"
value="add a row">

</form>
</body>
</html>

%%%%%%%%%%%%%%% read more about adding rows to a table


Message from vbgunz
Most recent post: 10/27/2007
3 authors and 4 replies.

function operator(a, b) {
return a + b;
}

without the use of eval, how'd you change the + operator into say
* ? If you cannot pass operators in any form what'd be the best
thing to do here or'd the best thing to do in this case is use
eval? read more about How to Pass an Operator e.g., * / + -


Message from dennis.sprengers
Most recent post: 10/27/2007
3 authors and 3 replies.

I'm trying to write a little script that reads the searchterms from
the document.referrer. But when I run it, I get no alerts. What am I
doing wrong? All help is appreciated :-)
-----------------------------------------------------
detectSearch("http://www.google.com?q=dattum");

var sniffs = {
'/google\./i' : 'q',
'/yahoo\./i' : 'p'
}

function detectSearch(uri) {
for (var sniff in sniffs) {
if (uri.match(sniff)) {
alert(getArg(uri, sniffs[sniff]));
}
}
}

function getArg(uri, arg) {
var args = [];
uri = uri.substr(uri.indexOf("?") + 1, uri.length);
for (var I = 0; I < uri.split("&").length; i++) {
if (uri.split("&")[i].split("=")[0] == arg) {
return uri.split("&")[i].split("=")[1];
}
}
}
----------------------------------------------------- read more about regex match function does not return any output


Message from Sue
Most recent post: 10/27/2007
4 authors and 4 replies.

Hi,

I'm new to JAVAscript and what I want to do is when user press F1 key,
it'll show the help page. Can anyone show me the JAVAscript code.
The link of the help page is help/work/Default_CSH.htm#messageBar
Thanks. read more about F1 key to go to a link


Message from scowat
Most recent post: 10/26/2007
3 authors and 5 replies.

I am dynamically updating the contents of cells to achieve a scrolling
effect, like this:

<html>
<body>
<script lang=JAVAscript>
function scroll(){
var firstrowcell1 = document.getElementById('1-1').innerHTML;
var firstrowcell2 = document.getElementById('1-2').innerHTML;
for (var x = 1; x < 3; x ++)
{
document.getElementById(x+'-1').innerHTML = document.getElementById((x
+1)+'-1').innerHTML;
document.getElementById(x+'-2').innerHTML = document.getElementById((x
+1)+'-2').innerHTML;
}
document.getElementById(x+'-1').innerHTML = firstrowcell1;
document.getElementById(x+'-2').innerHTML = firstrowcell2;
}
function scrollcont(){
setInterval('scroll()',1000);
}
function showinnerhtml(){
alert(document.getElementById("1-2").innerHTML);
}
</script>

<table>
<tr>
<td id='1-1'>Line 1</td>
<td id='1-2'><img src='numbers/1.gif' onmouseover="return escape('This
is line 1')">
</td>
</tr>
<tr>
<td id='2-1'>Line 2</td>
<td id='2-2'><img src='numbers/2.gif' onmouseover="return escape('This
is line 2')">
</td>
</tr>
<tr>
<td id='3-1'>Line 3</td>
<td id='3-2'><img src='numbers/3.gif' onmouseover="return escape('This
is line 3')">
</td> read more about InnerHTML doesn't return Onmouseover


Message from paul
Most recent post: 10/26/2007
2 authors and 2 replies.

Hello,
I am launching a webage with my url. Then in JAVAscript I want to hide
the toolbars and menubar. Is this possible after the page has
launched.

I know window.open() does this but because of the way our application
is I have to do it once page has loaded.

Thanks. read more about Hide IE toolbars, menubar after page has loaded


Message from Dr J R Stockton
Most recent post: 10/26/2007
4 authors and 5 replies.

In current JAVAscript, the handling of date and time, whilst powerful,
has some minor flaws and several omissions. In particular, while the
lack of ISO 8601 support can be dealt with in code, it's often done
inefficiently or wrongly.Date-handling suggestions for ECMAScript 4 or 5 :-

document.sourceDateHeader
A string copying, exactly, the data part of the Last-Modified
header. Require that new Date(string) shall always read it
correctly (it probably always complies already).

Consider the possibility of a variant so that, for a page constructed at
run-time, one might be able to get both the instant of design and the
instant of constructing the data ???

Granted, "document." is a DOM matter. So :

Dobj.setSourceDate
Dobj is loaded from the Last-Modified header.

Dobj.getSourceDate
Return the date/time in the same standard form.Let Dobj be a Date Object. LCT is Local Civil Time. Implement, for ISO
8601, routines like these :-

Dobj.toISOlctString()
Returns "yyyy-mm-dd hh:mm:ss +-offset", local civil time

Dobj.toISOutcString()
Returns "yyyy-mm-dd hh:mm:ss UTC", UTC/GMT

Dobj.toISOlctOrdinalString()
Returns "yyyy-ddd hh:mm:ss +-offset", local civil time

Dobj.toISOutcOrdinalString()
Returns "yyyy-ddd hh:mm:ss UTC", UTC/GMT

Dobj.toISOlctWeekString()
Returns "yyyy-Www-dd hh:mm:ss +-offset", local civil time

Dobj.toISOutcWeekString()
Returns "yyyy-W read more about ECMAScript 4+ Date proposals


Message from Edward Diener
Most recent post: 10/26/2007
7 authors and 18 replies.

Is there a way in JAVAscript, or perhaps in HTML, to force a browser to
re-render an image on an HTML page after a round-trip between the client
and the server ?

In my particular case, the image is changing on the server although the
URL for it remains the same, but the browser is still displaying the old
image from its cache rather than the new image from its URL location. read more about Forcing a browser to re-render an image from its URL location andnot from the browser's cache


Message from Nick
Most recent post: 10/26/2007
2 authors and 4 replies.

I have been tasked to figure out a way to communicate from a
JAVAScript /XUL client to a server, but without using a web server.I have been researching different possibilities, and I have come upon
<a href = "http://aflax.org">aflax</a>, which is a library for
imbedding flash in JAVAScript. So far I have been able to get it to
connect, but only if the server script is running locally along with
the flash content and client. I am using the example of a chat
program at aflax.org - http://aflax.org/examples/sockets/sockets.html
. you can see the example there but unfortunately the demo doesn't
work, and Aflax forums haven't provided a response.1) Why should the HTML file (with JAVAScript and Aflax) act
differently when it is opened as a file:// as opposed to on a
localhost web server? It doesn't connect to the server when I simply
open the file from my filesystem rather than being served it on a web
server. The Fir