473,326 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

newby question joining variables and strings together

im pretty ne to java script - so please be gentle :)

basically what i want to do is construct an action in a function using a
variable sent to that function
ok - what i want to do is

function ($number)
{
form1.button[add in the $number here].disabled=true;
}

say $number was 34, so in effect i would end up with

function ($number)
{
form1.button34.disabled=true;
}

i have tried all sorts but cnt seem to get the result i want - any advice
would be great

Sep 21 '05 #1
6 1406

chris wrote:
im pretty ne to java script - so please be gentle :)

basically what i want to do is construct an action in a function using a
variable sent to that function
ok - what i want to do is

function ($number)
{
form1.button[add in the $number here].disabled=true;
}

say $number was 34, so in effect i would end up with

function ($number)
{
form1.button34.disabled=true;
}

i have tried all sorts but cnt seem to get the result i want - any advice
would be great


I believe the effect you want to achieve is the following:

function myFunc(btnNum)
{
document.forms["formName"].elements["button" + btnNum].disabled =
true;
}

Hope this helps. :)

Sep 21 '05 #2
Lee
chris said:

im pretty ne to java script - so please be gentle :)
It's Javascript, not "java script". The distinction is important
because otherwise people get the impression that it is somehow
related to Java.

basically what i want to do is construct an action in a function using a
variable sent to that function

ok - what i want to do is

function ($number)
{
form1.button[add in the $number here].disabled=true;
}

say $number was 34, so in effect i would end up with

function ($number)
{
form1.button34.disabled=true;
}

i have tried all sorts but cnt seem to get the result i want - any advice
would be great


form1.button34.disabled is not a string. It's a reference in "dot notation",
and may not include variables. To do what you want, you need to use "square
bracket notation". You should also always refer to forms in relation to the
document, not as if the form reference was a global variable:

function disableButton(n) {
document.form1.elements["button"+n].disabled=true;
}

Sep 21 '05 #3
Thanks All, just wat i needed to know
--
¼á
"Lee" <RE**************@cox.net> wrote in message
news:dg*********@drn.newsguy.com...
chris said:

im pretty ne to java script - so please be gentle :)


It's Javascript, not "java script". The distinction is important
because otherwise people get the impression that it is somehow
related to Java.

basically what i want to do is construct an action in a function using a
variable sent to that function

ok - what i want to do is

function ($number)
{
form1.button[add in the $number here].disabled=true;
}

say $number was 34, so in effect i would end up with

function ($number)
{
form1.button34.disabled=true;
}

i have tried all sorts but cnt seem to get the result i want - any advice
would be great


form1.button34.disabled is not a string. It's a reference in "dot
notation",
and may not include variables. To do what you want, you need to use
"square
bracket notation". You should also always refer to forms in relation to
the
document, not as if the form reference was a global variable:

function disableButton(n) {
document.form1.elements["button"+n].disabled=true;
}

Sep 22 '05 #4
["Followup-To:" header set to alt.comp.lang.javascript.]
On 2005-09-21, chris <so*****@here.com> wrote:
im pretty ne to java script - so please be gentle :)

basically what i want to do is construct an action in a function using a
variable sent to that function
ok - what i want to do is

function ($number)
{
form1.button[add in the $number here].disabled=true;
}

say $number was 34, so in effect i would end up with

function ($number)
{
form1.button34.disabled=true;
}


this appears to be what you are trying to di,
it may work (I have not tested it).
but it is non-standard and will cause warnings in mozilla, and may not at all in
other browsers.

function ($number)
{
eval("form1.button"+$number+".disabled=true;");
}

you should be using document.GetElementById

this means giving any element you want to refer to an id tag.
that means you can have non-submitted form inputs by not giving
them a name tag.

Bye.
Jasen
Oct 16 '05 #5
Lee
Jasen Betts said:

["Followup-To:" header set to alt.comp.lang.javascript.]
On 2005-09-21, chris <so*****@here.com> wrote:
im pretty ne to java script - so please be gentle :)

basically what i want to do is construct an action in a function using a
variable sent to that function
ok - what i want to do is

function ($number)
{
form1.button[add in the $number here].disabled=true;
}

say $number was 34, so in effect i would end up with

function ($number)
{
form1.button34.disabled=true;
}


this appears to be what you are trying to di,
it may work (I have not tested it).
but it is non-standard and will cause warnings in mozilla, and may not at all in
other browsers.

function ($number)
{
eval("form1.button"+$number+".disabled=true;");
}

you should be using document.GetElementById

this means giving any element you want to refer to an id tag.
that means you can have non-submitted form inputs by not giving
them a name tag.


You should never use eval() to access a form element, and using
getElementById() is usually almost as bad. Use:

document.form1.elements["button"+$number].disabled=true;

Oct 16 '05 #6
Jasen Betts said the following on 10/15/2005 8:48 PM:

["Followup-To:" header set back to the legitimate comp.lang.javascript.]
["Followup-To:" header set to alt.comp.lang.javascript.]
On 2005-09-21, chris <so*****@here.com> wrote:
im pretty ne to java script - so please be gentle :)

basically what i want to do is construct an action in a function using a
variable sent to that function
ok - what i want to do is

function ($number)
{
form1.button[add in the $number here].disabled=true;
}

say $number was 34, so in effect i would end up with

function ($number)
{
form1.button34.disabled=true;
}
this appears to be what you are trying to di,
it may work (I have not tested it).
but it is non-standard and will cause warnings in mozilla, and may not at all in
other browsers.

function ($number)
{
eval("form1.button"+$number+".disabled=true;");
}


As Lee pointed out, NEVER use eval to access form elements.
you should be using document.GetElementById
syntax error. It is document.getElementById
this means giving any element you want to refer to an id tag.
that means you can have non-submitted form inputs by not giving
them a name tag.


Or, you get both by giving it a name *attribute*, then use the forms
collection to access it.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Oct 16 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Jack | last post by:
Hi, I need to pass multple variables in a link in order to go to a asp page with the two varables. The following are the values of the variables using response.write: <%'Response.Write Mypage...
2
by: James | last post by:
Can anyone please shed some light on the following... I have a framework that uses dynamically created tables, named using an incremental "attribute set ID", as follows: attrdata_1 attrdata_2...
5
by: Ross A. Finlayson | last post by:
Hi, I'm scratching together an Access database. The development box is Office 95, the deployment box Office 2003. So anyways I am griping about forms and global variables. Say for example...
9
by: robbie.carlton | last post by:
Hello! I've programmed in c a bit, but nothing very complicated. I've just come back to it after a long sojourn in the lands of functional programming and am completely stumped on a very simple...
6
by: Ryan Smith | last post by:
I am trying to store a string into a string variable via the following code however am receiving an error and cant figure out what i am doing wrong. Any feedback is greatly appreciated. Line...
5
by: Ian Davies | last post by:
Hello I am trying to update a session, ie everytime the page is resubmitted I want the current selected value from a list to be appended to the old session value. I have the following code but am...
2
by: Supermansteel | last post by:
I am joining these 2 tables together in Access 2003 and can't figure out the exact way of writing this script......Can anyone help? I have the following SQL: SELECT...
13
by: SUBHABRATA | last post by:
Dear Group, I am trying the following code line: def try2(n): a1=raw_input("PRINT A STRING:") a2=a1.split() a3="God Godess Heaven Sky" for x in a2: a4=a3.find(x) if a4>-1: a5=a3
7
by: sam.barker0 | last post by:
Hi, I tried to use the java approach to join 2 strings int w=0; string z="blah " + w + "blah " but this gives me an error but this works string z("blah"); z+=w;
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.