HighDots Forums  

help

Javascript JavaScript language (comp.lang.javascript)


Discuss help in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Bob
 
Posts: n/a

Default help - 06-08-2004 , 10:04 AM






I tried this in <input name="some_name" type="text" value=""
onChange="auto_select(0);">

but it gives a syntax error.


var cb = this.form.name
alert( "name=" + cb )


--
-------------------------------------------------------
Remove .NOSPAM from my email address to reply directly.

Reply With Quote
  #2  
Old   
Ivo
 
Posts: n/a

Default Re: syntax error, help - 06-08-2004 , 10:29 AM






"Bob" wrote
Quote:
I tried this in <input name="some_name" type="text" value=""
onChange="auto_select(0);"

but it gives a syntax error.


var cb = this.form.name
alert( "name=" + cb )
Hello Bob, not sure what you are trying to achieve here, but there are a
couple of things we can do about that. Could you please explain what you
would like to happen, what happens instead, and perhaps provide a bit more
code because it seems we are missing some relevant pieces. What is
auto_select(), are you sure the element referenced as "this" comes through
correctly?
Also 'help' isn't the most helpful subject line .
HTH
Ivo




Reply With Quote
  #3  
Old   
kaeli
 
Posts: n/a

Default Re: help - 06-08-2004 , 11:14 AM



In article <tHjxc.27261$sS2.823079 (AT) news20 (DOT) bellglobal.com>,
bob.lockie.NOSPAM (AT) mail (DOT) com enlightened us with...
Quote:
I tried this in <input name="some_name" type="text" value=""
onChange="auto_select(0);"

but it gives a syntax error.


var cb = this.form.name
'this', in a function, might not refer to what you thought it referred
to. I don't think it refers to the control, which is what that code
_seems_ to be thinking.

Post more code or a URL.

--
--
~kaeli~
Why do people who know the least know it the loudest?
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace



Reply With Quote
  #4  
Old   
Bob
 
Posts: n/a

Default Re: syntax error, help - 06-09-2004 , 10:26 AM



On 06/08/04 10:29 Ivo spoke:
Quote:
"Bob" wrote

I tried this in <input name="some_name" type="text" value=""
onChange="auto_select(0);"

but it gives a syntax error.


var cb = this.form.name
alert( "name=" + cb )


Hello Bob, not sure what you are trying to achieve here, but there are a
couple of things we can do about that. Could you please explain what you
would like to happen, what happens instead, and perhaps provide a bit more
code because it seems we are missing some relevant pieces. What is
auto_select(), are you sure the element referenced as "this" comes through
correctly?
function auto_select() {
// var cb = this.forms[0].elements["some_name"].name
var cb = this.form.name

alert( "name=" + cb )
}

I want to call auto_select when text is changed in the text field.
I tried var cb = this().form.name but I got "object is not function.



--
-------------------------------------------------------
Remove .NOSPAM from my email address to reply directly.


Reply With Quote
  #5  
Old   
Lee
 
Posts: n/a

Default Re: syntax error, help - 06-09-2004 , 11:37 AM



Bob said:
Quote:
On 06/08/04 10:29 Ivo spoke:
"Bob" wrote

I tried this in <input name="some_name" type="text" value=""
onChange="auto_select(0);"

but it gives a syntax error.


var cb = this.form.name
alert( "name=" + cb )


Hello Bob, not sure what you are trying to achieve here, but there are a
couple of things we can do about that. Could you please explain what you
would like to happen, what happens instead, and perhaps provide a bit more
code because it seems we are missing some relevant pieces. What is
auto_select(), are you sure the element referenced as "this" comes through
correctly?

function auto_select() {
// var cb = this.forms[0].elements["some_name"].name
var cb = this.form.name

alert( "name=" + cb )
}

I want to call auto_select when text is changed in the text field.
I tried var cb = this().form.name but I got "object is not function.
What are you trying to find the name of, the text field, or the
form that contains it? You've come closest to getting the name
of the form, but I'm not sure that's what you want.

In that context "this" refers to auto_select(), not the form field.
In the context of the onchange event handler function, "this" does
refer to the field, so you can have that function pass the reference
to auto_select():

<input name="some_name"
type="text"
value=""
onchange="auto_select(this)">

function auto_select(field) {
var cb = field.name
alert( "name=" + cb )
}



Reply With Quote
  #6  
Old   
Bob
 
Posts: n/a

Default Re: syntax error, help - 06-09-2004 , 02:39 PM



Quote:
What are you trying to find the name of, the text field, or the
form that contains it? You've come closest to getting the name
of the form, but I'm not sure that's what you want.
I want the name of the text field.


Quote:
In that context "this" refers to auto_select(), not the form field.
In the context of the onchange event handler function, "this" does
refer to the field, so you can have that function pass the reference
to auto_select():

input name="some_name"
type="text"
value=""
onchange="auto_select(this)"

function auto_select(field) {
var cb = field.name
alert( "name=" + cb )
}

Thanks, got it.


--
-------------------------------------------------------
Remove .NOSPAM from my email address to reply directly.


Reply With Quote
  #7  
Old   
Bob
 
Posts: n/a

Default Re: syntax error, help - 06-09-2004 , 02:55 PM



function auto_select( field, index ) {
var cb = field.form.elements["selectID"].name

alert( "name=" + cb )
}


</script>

<input name="content_216" type="text" value="1" onChange="auto_select(
this, 0);">

<input name="content_217" type="text" value="2" onChange="auto_select(
this, 0);">

<input name="selectID" value="216" type="checkbox">
<input name="selectID" value="217" type="checkbox">

There is a corresponding checkbox for every text entry field and what I
want is to make the checkbox selected if the text is changed.



--
-------------------------------------------------------
Remove .NOSPAM from my email address to reply directly.

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.