Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variable placement 1

Status
Not open for further replies.

mak2112

IS-IT--Management
Aug 8, 2001
46
I have created an html coupon where the coupon code needs to be changed based on what company i give it to. I figured if i could get that value to be a variable, i could have someone else change the variable value in order to apply it to another company. is this possible, and if so, what would be the best way to start. Basically what i would really like is to create a word document that will have a hyperlink back to the coupon, so i assume the variable that will be used will somehow be passed into the coupon from the hyperlink.

if you have any suggestions that would be great.

thanks
 
This can easily be done through parameter passing using the page's URL, and little bit of JavaScript.

First, here's a good tutorial:
Or you can find dozens of other tutorials by googling "parameter passing URL tutorial"

The link in the word file will have to include a variable at the end of the URL preceded by a question mark.

For example:
where theParameter is the coupon number.

The following code will extract the parameter, and place it into theVariable.

function MM_setParameterSub() {
var theVariable = location.search.substr(1).split("?");
}

Next you'll have to test theVariable:

if (theVariable == 'couponNumberOne') {
//code for coupon number one.
}

If you have any other questions, let me know.
 
thanks for your help, the only problem i have left is initializing the variable. where do i do that?
 
With JavaScript, like Java you don't need to initialize the variable at all. The variable type conforms to whatever you happen to put into it.

The line: var theVariable

declares the variable. That's all you'll need to do.
 
sorry about the delay but i was away. i am a bit confused. as to where i should put the &quot;if&quot; statement and what needs to precede it. I assume it is within the <body> of the html code. i also guess i need to initialize the javascript language as well? i was wondering if you knew any examples for this type url passing
 
just wanted to say thanks, i did figure out what i needed to do, as i was able to look up some help for &quot;url parameter passing&quot;.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top