/    Sign up×
Community /Pin to ProfileBookmark

Calling variable in a string

I have a function:
<SCRIPT language=”JavaScript1.2″>
function addNew() {
var tableName = document.add.TableName.value;
alert(tableName);

document.add.action=”/Web/Workflow?TableName=”;
document.add.method=”post”;
document.add.target=”list”;

var tableName = document.add.TableName.value;
alert(tableName);

document.add.submit();
}

</SCRIPT>
I want to use the variable ‘tableName’ in
document.add.action=”/Web/Workflow?TableName=variable”;
How can I do this?

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@Khalid_AliJul 21.2003 — Like this

document.add.action="/Web/Workflow?TableName="+TableName;
Copy linkTweet thisAlerts:
@miliauthorJul 21.2003 — Thanks Khalid..

I have something like this and it does not work for me

document.add.action="/Web/Workflow?TableName=+TableName&amp;action="+TableNameNew;

I'm trying to call the variable for the "action" parameter and append the variable with New
Copy linkTweet thisAlerts:
@NevermoreJul 21.2003 — [i]Originally posted by mili [/i]

[B]

I have something like this and it does not work for me



document.add.action="/Web/Workflow?TableName=+TableName&amp;action="+TableNameNew;

I'm trying to call the variable for the "action" parameter and append the variable with New [/B][/QUOTE]


If I understand you correctly, you need this:

document.add.action="/Web/Workflow?TableName="+TableName+"&action="+TableNameNew;
Copy linkTweet thisAlerts:
@Khalid_AliJul 21.2003 — [i]Originally posted by mili [/i]

[B] document.add.action="/Web/Workflow?TableName=+TableName&amp;action="+TableNameNew;



[/B]
[/QUOTE]


You have to remember how to concatenate strings in javascript.

"this is a string "

" this is a second string"

var IamAVariable = "I am a variable";

you will always have to make sure that you follow the pattern now to concatenate the strings and variable above this is what you wil need to do.

"this is a string "+IamAVariable+ " this is a second string"

now see the above description and then try to resconstruct your action string
Copy linkTweet thisAlerts:
@miliauthorJul 21.2003 — Thanks...but I get this error TableNameNew is undefined.

I'm trying to append the variable with the word New.
×

Success!

Help @mili spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...