What exactly are you trying to do? You can control which element is selected
at runtime with something like...
<script>
function SelectOption(){
document.FormName.SelectBoxName.options.selectedIndex = 0;
}
</script>
....where 0 is the index of the available options.
HTH,
Steve
----- Original Message -----
From: "John Murphy" <john@...>
To: <JS-Jive@onelist.com>
Sent: Tuesday, February 08, 2000 1:37 PM
Subject: Using JavaScript in a Select Box?
> From: "John Murphy" <john@...>
>
> Is it possible using Java script or any other method to enable a dropdown
> list to select results based on more than just the first character?
>
> Thanks in advance for any help.
>
> John Murphy
>
>
> --------------------------- ONElist Sponsor ----------------------------
>
> Unique Valentine gifts, available now at eGroups.
> <a href=" http://clickme.onelist.com/ad/SparksValentine2 ">Click Here</a>
>
> ------------------------------------------------------------------------
>
> Community email addresses:
> Post message: JS-Jive@onelist.com
> Subscribe: JS-Jive-subscribe@onelist.com
> Unsubscribe: JS-Jive-unsubscribe@onelist.com
> List owner: JS-Jive-owner@onelist.com
>
> Shortcut URL to this page:
> http://www.onelist.com/community/JS-Jive
>
>
Is it possible using Java script or any other method to enable a dropdown
list to select results based on more than just the first character?
Thanks in advance for any help.
John Murphy
hehe INST is my new heading for Instruction... i figure i'm basically
posting a small disertation every couple of days (hey it sure beats working
:) so i might as well let everyone know that it's a 'for learning' post
rather than an 'i'm helping only your problem' post. lemme know what you
guys think of the 'lessons' & i'll try & add a bit more instruction to the
next posts. :)
arrays are definately where it's at, and when combined with objects, they
work great with cf. This works well for loading a bunch of data onto one
page & using js to display it instead of going back to the server each time.
heres a bit of code i use to build objects in Javascript. ( there is an
explaination at the end)
<script language=javascript>
function recordOBJ(boat,status,lastUseDate)
{
this.boat=boat;
this.status=status;
this.lastUseDate=lastUseDate;
return this;
}
boatArray=new Array( new recordOBJ("titanic","sunk","1912"),
new recordOBJ("Queen Elizibeth","active","2000"),
new recordOBJ("Cadillac D'ville","retired","ca 1990?")
)
function alertSomething()
{
// remember that in JS, the first element is 0 not 1 !!
alert(boatArray[0].boat); // this will pop up "titanic"
alert(boatArray[2].lastUseDate); // this will show "ca 1990"
}
</script>
the real keys here are the use of the object 'this' and the keyword NEW
(only in lower case). when using this.element, you are creating a new class
inside the function. then, when 'return this;' is encounterd, that 'class'
is passed back & basically becomes an object. when the keyword NEW is
encountered, a whole new memory allocation is created for that
class/object. when used in an array, you have to use NEW or you will get
some strange results... (for higher learning, try taking NEW out &
seeing/trouble shooting the results & figure out what actually happens)
now, when accessing the array, some things to keep in mind. to get the
number of elements in the array, you can use the .length property. for
example:
alert(boatArray.length);
this is handy when you need to loop through your array in search of
something. but keep in mind that the first element is 0 and the last
element is array.length - 1 very important when setting up your loops &
debugging. for example: you might think that this would work:
for(i=0;i<=boatArray.length;i++){alert(boatArray[i].boat);}
and it in fact will work.. untill the very last iteration. you'll wind up
gettin an error that basically says boatArray[3] doesnt exist. this is
because even though there are 3 elements, element 3 is really element 4
(remember that 0 is the first number!!!) so the easy fix for this is to use:
for(i=0;i<boatArray.length;i++){alert(boatArray[i].boat);}
now, it'll stop looping 1 number before the value of boatArray.length...
which is probably a good thing considering thats the end of the array :).
one other thing to remember. an array can store any kind of data wether
it's user defined (like an object) or system defined( strings, numbers
etc.) for example:
myArray=new Array(1,2,5,4,78,98,43,75);
yourArray=new Array("this","is","an","array","test");
alert(myArray[2]); //will give you '5'
alert(myArray[myArray.length-1]); //will give you '75'
alert(yourArray[0]);// will display "this"
alert(yourArray[4]);// will display "test"
the reason objects instead of basic data types tend to be a bit cleaner is
because if you do something like this:
alert(yourArray); // you'll get "'this','is','an','array','test'"
whereas when using objects if you try:
alert(boatArray); // you'll get "[object],[object],[object]"
which is sometimes easier to debug & there's less confusion when there are
commas & quotes involved.
now, to apply what you know, try doing these 'projects'
1) create a 'sub' object that handles date data types.. for example:
boatArray[1].dateItSunk.month;
but still be able to access other members values like:
boatArray[1].name
2) try using CF to generate the javascript & populate it with data.
things to look out for:
1) quotes in the data
2) the comma before you start & after you end (once you try this,
you'lll understand what i'm talking about)
3) make it even more dynamic by using a select box to select the record you
want to view & load the individual data elements into text boxes.
hey one day i'll teach programming courses.. i just need to get a degree
first.. so till then i'll try & corrupt you guys first :)
have fun & good luck.
-chris
ps questions comments rants & raves to porter@...
<snip>
Greg,
Thanks too much for you attention and explanation.
Now, I'll study how can I create an array, 'cause I am so newbie :)
And I'll forget about others kinds of fields at the momment.
One thing for time :)
After, I'll send others doubts.
Thanks
Dan
At 13:30 06/02/2000 -0500, you wrote:
>Dan,
>
>Javascript can definitely loop. You need not worry about the field
>names as they are all available within the Document Object Model.
>
>There are few kinds of loops in JS, but for what you are trying to do,
>you can use the elements collection. The elements collection is an
>array of all the buttons, inputs, and selects in a form.
>
>To do this, you would loop like this:
>
>for (var j=0; j<document.ficha.elements.length; j++) {
> document.ficha.elements[j] (this lets you address the individual
>elements)
>}
>
>If you want to check for all different kinds of fields, etc. you will
>have to write some code to check the type of the element and then
>check the value.
>
>HTH,
>Greg
hi list! this is my first post. here goes :
i have a frameset with 2 frames tiled horizontally. The left frame contains
a CFTree applet show categories of products. The right frame the contents of
each category when the category is clicked.
i have functions to add/delete/edit the category, which is performed on the
right frame. When the actions are done, the right frame displays the "Done"
message and refreshes the left frame to show the changes. the problem is
that this refreshing function does not work in Netscape 4+.
the CFTree is enclosed in a form. so i used submit() and click() method to
submit the left frame form in order to refresh it, but somehow, netscape
does not perform this functions when called from the right. both methods
worked in IE.
is there an alternative?
thanks
Ken M. Mevand
Web Developer
geekabyte@...
__________________________________________________
Do You Yahoo!?
Talk to your friends online with Yahoo! Messenger.
http://im.yahoo.com
dan,
:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: From: Dan G. Switzer, II <dswitzer@...>
:
: The "return" statement is used to return a value
: to given command. In this instance, you're return
: true is completely unnecessary since "return true;"
: is the default for any command that doesn't fail.
:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
actually, you are incorrect in this instance. the default action for the
browser in regard to window.status is to display the value of the HREF
attribute. in order to override that and display you're own text with the
onMouseover handler, you must tell the browser to ignore the HREF value and
use yours instead. you do this by returning true to the onMouseover
handler. i know this is completely backwards to how return is typically
used, but that's the way it is.
in contrast, you don't have to return true to setting the status to nothing
with the onMouseout handler because clearing the status upon mousing out is
the default action.
here's an example of the two together:
<A HREF="some_doc.html"
onMouseover="window.status='this is some doc'; return true"
onMouseout="window.status=''"
>some doc</A>
i hope this clarifies things a bit.
thanks,
: jeff.howden
: web.development.professional
: evolt.org.member
:
: the.best.looking.developers.on.the.net
:
: http://evolt.org/
: jeff@...
Dan,
Javascript can definitely loop. You need not worry about the field
names as they are all available within the Document Object Model.
There are few kinds of loops in JS, but for what you are trying to do,
you can use the elements collection. The elements collection is an
array of all the buttons, inputs, and selects in a form.
To do this, you would loop like this:
for (var j=0; j<document.ficha.elements.length; j++) {
document.ficha.elements[j] (this lets you address the individual
elements)
}
If you want to check for all different kinds of fields, etc. you will
have to write some code to check the type of the element and then
check the value.
HTH,
Greg
----- Original Message -----
From: Daniel Chicayban <dan@...>
To: <JS-Jive@onelist.com>
Sent: Sunday, January 30, 2000 5:28 PM
Subject: Can JavaScript loop?
> From: Daniel Chicayban <dan@...>
>
> Hi people
>
> I wanna create a function to verify data in a form.
> The form is too long and 'cause it i wanna know if can javascript
run a
> loop to make my work more easiest?
>
> I think that the problem is in the name of the inputs.
> Because they're variables.
>
> So I think: if i create an array with all form names.
> Can I write a script to catch the name of the form in array
> and process the script on a single line?
>
> 'Cause if I must to use array[1], array[2] etc...
> I'll drop in the same.
>
> Other question: can javascript verify
> if a radion button or checkbox was clicked?
>
> That's my poor function :)
>
> function verify() {
> if (document.ficha.Nome_professor.value == "") {
> alert("O campo Nome do Professor é obrigatório");
> document.ficha.Nome_professor.focus();
> return false;
> }
> }
>
> Thanks in advance.
> Dan
>
>
> --------------------------- ONElist
Sponsor ----------------------------
>
> eGroups' Valentine's Day Gift Guide - Shop Here Now:
> <a href=" http://clickme.onelist.com/ad/SparksValentine4 ">Click
Here</a>
>
> --------------------------------------------------------------------
----
>
> Community email addresses:
> Post message: JS-Jive@onelist.com
> Subscribe: JS-Jive-subscribe@onelist.com
> Unsubscribe: JS-Jive-unsubscribe@onelist.com
> List owner: JS-Jive-owner@onelist.com
>
> Shortcut URL to this page:
> http://www.onelist.com/community/JS-Jive
Hi people
I wanna create a function to verify data in a form.
The form is too long and 'cause it i wanna know if can javascript run a
loop to make my work more easiest?
I think that the problem is in the name of the inputs.
Because they're variables.
So I think: if i create an array with all form names.
Can I write a script to catch the name of the form in array
and process the script on a single line?
'Cause if I must to use array[1], array[2] etc...
I'll drop in the same.
Other question: can javascript verify
if a radion button or checkbox was clicked?
That's my poor function :)
function verify() {
if (document.ficha.Nome_professor.value == "") {
alert("O campo Nome do Professor é obrigatório");
document.ficha.Nome_professor.focus();
return false;
}
}
Thanks in advance.
Dan
List,
I have a request from a client to create a file upload progress bar/graph.
This will be used with the cf <cffile> upload.
The client would prefer something similar to the browser progress window
that displays when files are downloading.
Is this a something that can be called with js?
Kathleen
I seem to recall researching this a while back and coming up empty, but
I'll post the question here to see if anyone has done something similar.
Is there a 'simple' way to detect whether the contents of any field on a
form has changed? I know it can be done by examining each field, and I
believe I've done it in the past by adding an onChange() handler function
to every input field on a form and then setting a global boolean variable.
Adding the onChange() to every input field of existing (long) forms is
something I'd like to avoid.
I had hoped I could find a bit of code to use on any form that would set a
hidden form field when any form field is changed. What I'm trying to do
is create intranet applications that let users step through records and
would automatically save any changes without the user having to explicitly
do an update and without the server overhead of doing the update every
time a user moves off of a record.
Jim
I was just wondering if something similar to the link below would be
possible. I imagine the original solution is the closest. No big deal.
Thanks.
<a href="javascript:GetMyURL()">some link</a>
Jim
through some
-----Original Message-----
From: Brett Suwyn <brett@...>
To: JS-Jive@onelist.com <JS-Jive@onelist.com>
Date: Friday, February 04, 2000 3:49 PM
Subject: RE: Scripting <a href=>
>From: "Brett Suwyn" <brett@...>
>
>Jim,
> Not sure what you mean. I'll cover a couple interpretations below...
>
>1) You could use JavaScript to write the entire anchor tag, but to get it
to
>write just href attrib inside the anchor, stumps me. And just thinking
>about it makes me think there is a better way to do what your trying to
do.
>
>2) You can use JavaScript to read/write the anchor's href attribute
through
>DOM. I believe it's document.linkname.href where linkname used <a
>href="whatever.htm" name="linkname">.
>
>
>Do that help?
>
>Brett Suwyn
>mailto:brett@...
>
>
>> From: "Jim McAtee" <jmcatee@...>
>> In a related vein: Is there a way to have a javascript function return
a
>> string that could be used directly within the href? I tried it a
couple
>> ways but kept getting errors. This might just be a lack of
understanding
>> on my part of how the event model operates.
>
>
>
>
>--------------------------- ONElist Sponsor ----------------------------
>
>Want To Be Showered With Kisses?
>Visit eGroups Valentine Gift Guide
><a href=" http://clickme.onelist.com/ad/SparksValentine9 ">Click Here</a>
>
>------------------------------------------------------------------------
>
>Community email addresses:
> Post message: JS-Jive@onelist.com
> Subscribe: JS-Jive-subscribe@onelist.com
> Unsubscribe: JS-Jive-unsubscribe@onelist.com
> List owner: JS-Jive-owner@onelist.com
>
>Shortcut URL to this page:
> http://www.onelist.com/community/JS-Jive
>
Jim,
Not sure what you mean. I'll cover a couple interpretations below...
1) You could use JavaScript to write the entire anchor tag, but to get it to
write just href attrib inside the anchor, stumps me. And just thinking
about it makes me think there is a better way to do what your trying to do.
2) You can use JavaScript to read/write the anchor's href attribute through
DOM. I believe it's document.linkname.href where linkname used <a
href="whatever.htm" name="linkname">.
Do that help?
Brett Suwyn
mailto:brett@...
> From: "Jim McAtee" <jmcatee@...>
> In a related vein: Is there a way to have a javascript function return a
> string that could be used directly within the href? I tried it a couple
> ways but kept getting errors. This might just be a lack of understanding
> on my part of how the event model operates.
Thanks Brett. That works a charm.
In a related vein: Is there a way to have a javascript function return a
string that could be used directly within the href? I tried it a couple
ways but kept getting errors. This might just be a lack of understanding
on my part of how the event model operates.
Jim
-----Original Message-----
From: Brett Suwyn <brett@...>
To: JS-Jive@onelist.com <JS-Jive@onelist.com>
Date: Thursday, February 03, 2000 6:50 PM
Subject: RE: Scripting <a href=>
>From: "Brett Suwyn" <brett@...>
>
>Jim,
>
>Here you go....
>
><script language="JavaScript">
> function GotoURL(url) {
> window.location = url+'&<cfoutput>#cgi.query_string#</cfoutput>';
> }
></script>
>
><cfloop query="q">
> <a
href="javascript:GotoURL('mypage.cfm?item=#q.itemnum#');">#q.name#</a>
></cfloop>
>
>
>Brett Suwyn
>mailto:brett@...
>
>> From: "Jim McAtee" <jmcatee@...>
>>
>> I need to append a string to url's being referenced in an HREF. This
is
>> on a CF page and I want to pass along the same query string that was
>> passed in to this page. The reason I want to use a JavaScript function
is
>> that the query string may be several hundred characters and there may
be
>> several hundred links on the page, and I want to limit the size of the
>> page generated.
>
>
>--------------------------- ONElist Sponsor ----------------------------
>
>Unique Valentine gifts, available now at eGroups.
><a href=" http://clickme.onelist.com/ad/SparksValentine2 ">Click Here</a>
>
>------------------------------------------------------------------------
>
>Community email addresses:
> Post message: JS-Jive@onelist.com
> Subscribe: JS-Jive-subscribe@onelist.com
> Unsubscribe: JS-Jive-unsubscribe@onelist.com
> List owner: JS-Jive-owner@onelist.com
>
>Shortcut URL to this page:
> http://www.onelist.com/community/JS-Jive
>
actually steve .. per our thread on JS-jive :) return false; would be the
better return value for your reload script.. this is because someone may
want to use an href or an <input type=submit> button instead of a button.
if either of those use that function, the page may function imporperly.
Here is what i would do differently:
<script language="JavaScript">
function ReloadTree(){
parent.MainTree.location.reload();
return false;
}
</script>
<input type="button" value="Reload CFTree" onclick="return ReloadTree()">
or
<a href="" onClick="return ReloadTree();">Refresh</a>
or
<input type=submit value="Refresh" onClick="return ReloadTree();">
keep in mind that that is just prefrence speaking.. technically you can do
it either way and there is very little performance gain/loss either way.
-chris
At 03:10 PM 2/4/00 -0500, you wrote:
>You have to update your database before you can refresh the cftree with the
>new data. Here is the JavaScript that you will want to use to update the
>page, but you will have to call the function after the cfquery has executed.
>I don't think you will get fresh data putting it in the onsubmit in the form
>element...
>
>
><!--- Snip --->
>
><script language="JavaScript">
> function Reload(){
> parent.MainTree.location.reload();
> return true;
>}
></script>
>
><input type="button" value="Reload CFTree" onclick="ReloadTree()">
>
><!--- Snip --->
>
>
>The button is just an example of how to call the function. You can use
>onload or onunload in the body tag of a page as well...
>
>
>HTH,
>Steve
>
>PS. There's a new JavaScript list called JS-Jive that you can subscribe to.
>It was spawned from this list so there are a lot of CFers on it. Send a
>blank email to JS-Jive-subscribe@onelist.com to subscribe.
>
>----- Original Message -----
>From: "kw" <kwillyerd@...>
>To: <cf-talk@...>
>Sent: Friday, February 04, 2000 2:24 PM
>Subject: JavaScript? frame refresh
>
>
>> I have a frameset that has one frame on the left with a cftree in it. The
>> left frame is divided into two frames horizontally. They are initially
>> blank. A anchor tag in the tree brings up the detail for the record in a
>> form that allows change delete or add new record then updates the detail
>> form with the changed information. Is there a way in CF to update the
>> display of the tree in the original frame? or will that require
>JavaScript?
>> If JavaScript is required any hints? I've only done cut and paste
>> JavaScript.
>>
>> <Frameset cols="220,*">
>> <Frame name="MainTree" src="tree.cfm" noresize scrolling="no">
>> <frameset rows="*,*">
>> <Frame name="upper" src="Blank.cfm" noresize >
>> <Frame name="lower" src="Blank.cfm" noresize >
>> </frameset>
>>
>> </Frameset>
>>
>> Kevin Willyerd
>> kevin@...
>>
>> --------------------------------------------------------------------------
>----
>> Archives: http://www.eGroups.com/list/cf-talk
>> To Unsubscribe visit
>http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or
>send a message to cf-talk-request@... with 'unsubscribe' in
>the body.
>>
>
>---------------------------------------------------------------------------
---
>Archives: http://www.eGroups.com/list/cf-talk
>To Unsubscribe visit
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or
send a message to cf-talk-request@... with 'unsubscribe' in
the body.
>
Hi people!
It would like to congratulate the message of the Chris Porter and to
suggest something to the list.
The explanation of the Chris on "return true/false" was very good and the
suggestion is of that we
could try to send more learnings of that doubts.
For example: if you created one script, for more poor that it can seem, is
one script and then you would can post the script in the list and explain
each string of the code here, instead of using the list only to take off
doubts, because otherwise, we go to have the list with more problems than
solutions.
It's clearly that nobody needs to leave to send doubts, but what I want to
stimulate are the messages with explanations
Exactly that nobody asks, if you know a little of the language, you would
be excellent that you some thing sent a message explaining.
Congratulations to Chris and thanks for the explanation.
Hugs to all.
Daniel Chicayban
PS: sorry for poor english, that's not my first language.
Peter,
There are also several cross browser libraries that will help you do this.
I've done exactly what you're after on our CFUG site
(http://www.oacfug.org--check out the Member Directory or Meeting Minutes.)
You can do it without using a cross-browser library as well. I original did
it by using both IFRAME (IE) and ILAYER (NS) which allow you to load
external pages into the layer, but I was running into problems with trying
to overlap layers on top of those layers. Both of those tags will always
appear on "top" of other layers on the page, so I went with the DynAPI
library to get around the problem. However, if you're simplying wanting to
use the layer to retrieve a WDDX packet, or if you're not going to have any
layers that appear on top of the content in the layer, then you can use
IFRAME and ILAYER. Since each browser all supports one of the two tags, you
can use them both without a problem.
-Dan
+--------+---------------------------+
| name | Dan G. Switzer, II |
|company | PengoWorks.com |
| www | http://www.pengoworks.com |
| mailto | dswitzer@... |
+--------+---------------------------+
-----Original Message-----
From: Thompson, Peter [mailto:Peter.Thompson@...]
Sent: Friday, February 04, 2000 10:56 AM
To: 'JS-Jive@onelist.com'
Subject: Layers/DHTML
From: "Thompson, Peter" <Peter.Thompson@...>
I'm wondering if anyone has done anything with layers (IE5) that can make a
call to the server on the layer, but still appear as if it's being executed
on the client side (no foundation page reload)
Pete
--------------------------- ONElist Sponsor ----------------------------
Shop for your Valentine at eGroups.
<a href=" http://clickme.onelist.com/ad/SparksValentine6 ">Click Here</a>
------------------------------------------------------------------------
Community email addresses:
Post message: JS-Jive@onelist.com
Subscribe: JS-Jive-subscribe@onelist.com
Unsubscribe: JS-Jive-unsubscribe@onelist.com
List owner: JS-Jive-owner@onelist.com
Shortcut URL to this page:
http://www.onelist.com/community/JS-Jive
Peter,
I have done it before. It's pretty simple, with the exception of the
timing.
You will have to throw an IFRAME hidden in the page. What I did was
to submit to that page. What I do to get around all the readyState
crap and having to do loops to make sure the page is loaded.. in the
page that's called in the hidden frame, I write some Javascript code
out at the end of the page that copies the contents of the document,
or a <DIV> in that page, to the layer I want to look updated.
If you don't put the JS code in the IFRAME, then you will have to have
a loop running in the calling page that checks the readyState of the
body of the IFRAME. When you get "complete" for the readyState, then
you can copy the contents.
IFRAMEs are tricky because you are restricted from accessing the
content directly. But the way I described above works like a charm.
And that's it.
Greg
----- Original Message -----
From: Thompson, Peter <Peter.Thompson@...>
To: <JS-Jive@onelist.com>
Sent: Friday, February 04, 2000 10:56 AM
Subject: Layers/DHTML
> From: "Thompson, Peter" <Peter.Thompson@...>
>
> I'm wondering if anyone has done anything with layers (IE5) that can
make a
> call to the server on the layer, but still appear as if it's being
executed
> on the client side (no foundation page reload)
>
> Pete
>
> --------------------------- ONElist
Sponsor ----------------------------
>
> Shop for your Valentine at eGroups.
> <a href=" http://clickme.onelist.com/ad/SparksValentine6 ">Click
Here</a>
>
> --------------------------------------------------------------------
----
>
> Community email addresses:
> Post message: JS-Jive@onelist.com
> Subscribe: JS-Jive-subscribe@onelist.com
> Unsubscribe: JS-Jive-unsubscribe@onelist.com
> List owner: JS-Jive-owner@onelist.com
>
> Shortcut URL to this page:
> http://www.onelist.com/community/JS-Jive
I'm wondering if anyone has done anything with layers (IE5) that can make a
call to the server on the layer, but still appear as if it's being executed
on the client side (no foundation page reload)
Pete
> From: "Dan G. Switzer, II" <dswitzer@...>
>
> The best reference book on JavaScript is "JavaScript: The
> Definitive Guide"
> by O'Reilly. (Actually all the O'Reilly books are pretty good.)
I second that, this is the only JavaScript specific book you will need. Not
only does the reference section kick ass but the text itself is great source
for learning.
After you tackle that, pick up O'Reilly's "Dynamic HTML, The Definitive
Guide" by Goodman, The fun really begins when you incorporate your
JavaScript skills with CSS, CSS-P, and DOM :)
Brett Suwyn
mailto:brett@...
The best reference book on JavaScript is "JavaScript: The Definitive Guide"
by O'Reilly. (Actually all the O'Reilly books are pretty good.) It will list
in good detail which functions are support in which version of the
JavaScript spec. I know a couple of times it's saved me from hours and hours
of debugging. There are a few functions, which operate differently depending
on the version of the language you specify for that given script. With this
book, I would have pulled all my hair out more then once or twice...
-Dan
+--------+---------------------------+
| name | Dan G. Switzer, II |
|company | PengoWorks.com |
| www | http://www.pengoworks.com |
| mailto | dswitzer@... |
+--------+---------------------------+
-----Original Message-----
From: Steve Reich [mailto:steve.reich@...]
Sent: Thursday, February 03, 2000 9:22 PM
To: JS-Jive@onelist.com
Subject: Version 1.1 or 1.2?
From: "Steve Reich" <steve.reich@...>
How do can you tell the difference between JavaScript versions? Is there a
chart of functions that are new to 1.2? What are the differences? What's on
the horizon? Sorry.. but I have a ton of questions I've been wanting answers
to so be patient with me ;-) Thanks to everyone for participating!
Steve
_________________________________
"640K ought to be enough for anybody."
-Bill Gates, 1981
_________________________________
--------------------------- ONElist Sponsor ----------------------------
Don't buy your Valentine a Gift by clicking here.
<a href=" http://clickme.onelist.com/ad/SparksValentine11 ">Click Here</a>
------------------------------------------------------------------------
Community email addresses:
Post message: JS-Jive@onelist.com
Subscribe: JS-Jive-subscribe@onelist.com
Unsubscribe: JS-Jive-unsubscribe@onelist.com
List owner: JS-Jive-owner@onelist.com
Shortcut URL to this page:
http://www.onelist.com/community/JS-Jive
> if (foo > bar) return foo;
> else return bar;
I can't resist putting in my two cents:
Good programming practice holds that functions should have one and only
one return statement, like this:
if (foo > bar) returnValue = foo
else returnValue = bar
return returnValue
Similarly, there should only be one way to exit a loop. No sprinkling
those break statements around.
-David
________________________________________________________________
YOU'RE PAYING TOO MUCH FOR THE INTERNET!
Juno now offers FREE Internet Access!
Try it today - there's no risk! For your FREE software, visit:
http://dl.www.juno.com/get/tagj.
How do can you tell the difference between JavaScript versions? Is there a
chart of functions that are new to 1.2? What are the differences? What's on
the horizon? Sorry.. but I have a ton of questions I've been wanting answers
to so be patient with me ;-) Thanks to everyone for participating!
Steve
_________________________________
"640K ought to be enough for anybody."
-Bill Gates, 1981
_________________________________
Jim,
Here you go....
<script language="JavaScript">
function GotoURL(url) {
window.location = url+'&<cfoutput>#cgi.query_string#</cfoutput>';
}
</script>
<cfloop query="q">
<a href="javascript:GotoURL('mypage.cfm?item=#q.itemnum#');">#q.name#</a>
</cfloop>
Brett Suwyn
mailto:brett@...
> From: "Jim McAtee" <jmcatee@...>
>
> I need to append a string to url's being referenced in an HREF. This is
> on a CF page and I want to pass along the same query string that was
> passed in to this page. The reason I want to use a JavaScript function is
> that the query string may be several hundred characters and there may be
> several hundred links on the page, and I want to limit the size of the
> page generated.
I need to append a string to url's being referenced in an HREF. This is
on a CF page and I want to pass along the same query string that was
passed in to this page. The reason I want to use a JavaScript function is
that the query string may be several hundred characters and there may be
several hundred links on the page, and I want to limit the size of the
page generated.
Without using JavaScript this looks like:
...
<cfloop query="q">
<a href="mypage.cfm?item=#q.itemnum#&#cgi.query_string#">#q.name#</a>
</cfloop>
...
I figure that I'd expand cgi.query_string using CF within a JavaScript
function so that this text is included only once in the html generated for
the page. Any ideas how this can be done?
Thanks,
Jim
heres a very simple explaination for what & how return works. and some
examples at the end :)
when a function is created, you are basically taking a set of instructions
& making them so that you dont have to repeat them over and over. generally
you want some kind of status as to the result of those functions.. for
example lets say you were multiplying 2 numbers together. and for the sake
of argument, you want to make a function that does this so you dont have to
do it every time.
the first thing you need to decide on is what needs to be passed to the
function. in this case 2 numbers.. we'll call them foo & bar. now once
those numbers have been multiplied, you are gonna want that result. thats
where return comes in. when you use return, a value is 'passed back' from
the function. as you will see in this example:
<script language=javascript>
function multiply(foo, bar)
{
retVar=foo * bar;
return retVar;
}
function nowRunThis()
{
//now lets say we want to use our function to get the result of
//this equation: 2*2 + 4*4
myValue=multiply(2,2) + multiply(4,4);
alert(myValue);
}
</script>
as you can see, multiply() is passed two numbers, and gives back another
number. the number it gives back is it's RETURN VALUE.
in some cases all a function my be returning the result of a conditional
statement.. for instance, what if we wanted to test wether one number was
greater than another. as in this example:
function giveMeGreaterNumber(foo,bar)
{
if (foo > bar) return foo;
else return bar;
// if they are equal.. who cares which one comes back!
}
in other cases the function may be returning a status.. such as.
function isThisStringNull(myString)
{
if (myString.length==0) return true;
else return false;
}
one last thing before i go. the return value can be anything including
objects, array elements strings numbers boolean values.. but the important
thing to note is that you can only return 1 thing. by thing i mean 1
object, or 1 array or 1 string or 1 number etc..
hope this helps.
-chris
ps if you wanna learn javascript, i highly reccoment JavaScript For
Dummies. it is an excelent book that actually teaches very good principles
of javascript & code structure.. & is easy to understand.
At 02:59 PM 2/3/00 -0500, you wrote:
>From: "Steve Reich" <steve.reich@...>
>
>I have fumbled my way through a lot of complex JavaScripts and have written
>quite a bit of my own, all without, believe it or not, having the slightest
>clue what "return true" or "return false" mean or do. Can anyone explain
>this to me?
>
>Example:
>
><a href="help.htm" onmouseover="window.status='Click here for help'; return
>true">Help</a>
>
>
>
>Thanks,
>Steve
>
>
>--------------------------- ONElist Sponsor ----------------------------
>
>Get what you deserve with NextCard Visa. Rates as low as 2.9 percent
>Intro or 9.9 percent Fixed APR, online balance transfers, Rewards
>Points, no hidden fees, and much more. Get NextCard today and get the
>credit you deserve. Apply now. Get your NextCard Visa at
><a href=" http://clickme.onelist.com/ad/NextcardCreative1CI ">Click Here</a>
>
>------------------------------------------------------------------------
>
>Community email addresses:
> Post message: JS-Jive@onelist.com
> Subscribe: JS-Jive-subscribe@onelist.com
> Unsubscribe: JS-Jive-unsubscribe@onelist.com
> List owner: JS-Jive-owner@onelist.com
>
>Shortcut URL to this page:
> http://www.onelist.com/community/JS-Jive
>
Steve,
The "return" statement is used to return a value to given command. In this
instance, you're return true is completely unnecessary since "return true;"
is the default for any command that doesn't fail.
By return true or false to an event, you're able to continue or stop the
rest of the transaction from occurring. So for example, if you disable a
link from working, you could do:
<A HREF="./index.htm" onClick="return false;">Some Link</A>
Since we're returning "false" anytime the user click the link, the browser
will ignore triggering the link. However, it will still trigger any command
before the "return false;" command.
So, if you wanted a link to pop up a message "Hello World!", you could do
something like:
<A HREF="" onClick="alert('Hello World!'); return false;">Say "Hello
World!"</A>
Note, the alert() function is executed, but the browser does not execute the
jump to the next page.
You can also use "return" to pass values back to the calling command.
For example:
function addNumbers(x,y){
return x + y;
}
x = addNumbers(3,4);
alert(x); //displays 7
alert(addNumbers(3,4)); // displays 7 as well...
-Dan
+--------+---------------------------+
| name | Dan G. Switzer, II |
|company | PengoWorks.com |
| www | http://www.pengoworks.com |
| mailto | dswitzer@... |
+--------+---------------------------+
-----Original Message-----
From: Steve Reich [mailto:steve.reich@...]
Sent: Thursday, February 03, 2000 2:59 PM
To: JS-Jive
Subject: {JS-Jive} Return True/False?
From: "Steve Reich" <steve.reich@...>
I have fumbled my way through a lot of complex JavaScripts and have written
quite a bit of my own, all without, believe it or not, having the slightest
clue what "return true" or "return false" mean or do. Can anyone explain
this to me?
Example:
<a href="help.htm" onmouseover="window.status='Click here for help'; return
true">Help</a>
Thanks,
Steve
--------------------------- ONElist Sponsor ----------------------------
Get what you deserve with NextCard Visa. Rates as low as 2.9 percent
Intro or 9.9 percent Fixed APR, online balance transfers, Rewards
Points, no hidden fees, and much more. Get NextCard today and get the
credit you deserve. Apply now. Get your NextCard Visa at
<a href=" http://clickme.onelist.com/ad/NextcardCreative1CI ">Click Here</a>
------------------------------------------------------------------------
Community email addresses:
Post message: JS-Jive@onelist.com
Subscribe: JS-Jive-subscribe@onelist.com
Unsubscribe: JS-Jive-unsubscribe@onelist.com
List owner: JS-Jive-owner@onelist.com
Shortcut URL to this page:
http://www.onelist.com/community/JS-Jive
Steve,
The return value is that "returned" from a function or method.
You will use it a lot in your own functions. Say you create a
function:
function addPeriod(string) {
return string += '.';
}
What we did here is have the function return a value that is slightly
modified.
You would call this like:
newString = addPeriod(oldString);
Also, many of the built in functions will often return a value after
you use them. For example:
temp = window.open('tere.cfm');
temp contains a reference to the newly created window.
Another use is as you mentioned, to pass a Boolean. For example:
if (confirm("You are smart!") alert("Smartie!");
Here, the confirm function returns true if the user clicks OK. The
result is we get an alert.
Hope that helps a little.
Greg
----- Original Message -----
From: Steve Reich <steve.reich@...>
To: JS-Jive <JS-Jive@onelist.com>
Sent: Thursday, February 03, 2000 2:59 PM
Subject: {JS-Jive} Return True/False?
> From: "Steve Reich" <steve.reich@...>
>
> I have fumbled my way through a lot of complex JavaScripts and have
written
> quite a bit of my own, all without, believe it or not, having the
slightest
> clue what "return true" or "return false" mean or do. Can anyone
explain
> this to me?
>
> Example:
>
> <a href="help.htm" onmouseover="window.status='Click here for help';
return
> true">Help</a>
>
>
>
> Thanks,
> Steve
>
>
> --------------------------- ONElist
Sponsor ----------------------------
>
> Get what you deserve with NextCard Visa. Rates as low as 2.9 percent
> Intro or 9.9 percent Fixed APR, online balance transfers, Rewards
> Points, no hidden fees, and much more. Get NextCard today and get
the
> credit you deserve. Apply now. Get your NextCard Visa at
> <a href=" http://clickme.onelist.com/ad/NextcardCreative1CI ">Click
Here</a>
>
> --------------------------------------------------------------------
----
>
> Community email addresses:
> Post message: JS-Jive@onelist.com
> Subscribe: JS-Jive-subscribe@onelist.com
> Unsubscribe: JS-Jive-unsubscribe@onelist.com
> List owner: JS-Jive-owner@onelist.com
>
> Shortcut URL to this page:
> http://www.onelist.com/community/JS-Jive
I have fumbled my way through a lot of complex JavaScripts and have written
quite a bit of my own, all without, believe it or not, having the slightest
clue what "return true" or "return false" mean or do. Can anyone explain
this to me?
Example:
<a href="help.htm" onmouseover="window.status='Click here for help'; return
true">Help</a>
Thanks,
Steve
Since there doesn't seem to be any messages to this list yet, I'll send one
:).
For anyone interested, I have a JavaScript WDDX/Form library available at:
http://www.oacfug.org/users/dswitzer/forms/. This library automatically
handles serializing and deserializing of a form's content into WDDX. There
are several different examples of how the library can be used on the site.
Sincerely,
Dan G. Switzer, II
+--------+---------------------------+
| name | Dan G. Switzer, II |
|company | PengoWorks.com |
| www | http://www.pengoworks.com |
| mailto | dswitzer@... |
+--------+---------------------------+