473,898 Members | 3,068 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1432

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.c om...
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.j avascript.]
On 2005-09-21, chris <so*****@here.c om> 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.but ton"+$number+". disabled=true;" );
}

you should be using document.GetEle mentById

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.j avascript.]
On 2005-09-21, chris <so*****@here.c om> 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.but ton"+$number+". disabled=true;" );
}

you should be using document.GetEle mentById

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"+$numbe r].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.javas cript.]
["Followup-To:" header set to alt.comp.lang.j avascript.]
On 2005-09-21, chris <so*****@here.c om> 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.but ton"+$number+". disabled=true;" );
}


As Lee pointed out, NEVER use eval to access form elements.
you should be using document.GetEle mentById
syntax error. It is document.getEle mentById
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.javas cript 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
6703
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 & "<br>"%> Exp <%'Response.Write GrantID & "<br>"%>
2
3518
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 attrdata_3 etc, etc...
5
3356
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 I'm adding a customer. The Customer fields are mostly foreign keys that refer to primary keys in other tables, left join instead of junction tables at this point. So, when I want to add a customer record, I also need to add records to the other...
9
2052
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 function I'm trying to write. I'm writing a function that takes a string, and returns an array of strings which are the result of splitting the input on whitespace and parentheses (but the parentheses should also be included in the array as...
6
1159
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 49: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Line 50: Line 51: Dim strSQL As String = "INSERT INTO Investors (FNAME,LNAME,EMAIL,ADDRESS1,ADDRESS2," & _
5
3038
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 unable to get it to work. I dont know the correct syntac wher I have put the word 'PLUS'. <?php $_SESSION = $_SESSION PLUS $_POST;?> I have tried & but this doesnt work, or even && which I have seen in some
2
2275
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 PL_Input.Date_ID,Count(PL_Input.+PL_Input.+PL_Input.+PL_Input.+PL_Input.) AS FROM Country INNER JOIN PL_Input ON Country.Country_ID = PL_Input.Country_ID WHERE (((. & "" & . & "" & . & "" & . & "" & .) Like "*2*"))
13
1020
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
2000
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
9993
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9840
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11259
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10857
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10948
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10483
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8035
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7187
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5880
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...

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.