INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

passing an input variable to a querystring

passing an input variable to a querystring

(OP)
Hi All,

I have a link to a page and the url contains a parameter variable to pass to a querystring on another page

CODE

<a class="nav" href="../OEE/OEE_ChartYear.asp?cYear=2014" target="cpOTIF_Main" >OEE 2014</a> 
Obviously this will not work after the end of this year as it is passing 2014, I know I can create another link for 2015

CODE

<a class="nav" href="../OEE/OEE_ChartYear.asp?cYear=2015" target="cpOTIF_Main" >OEE 2014</a> 
However I was wondering if it is possible to ask the user what year they require when clicking the link. I know it is possible to use a form but I have several links like this and I did not want to create several forms.

I was wondering if something like this would work

CODE

<a class="nav" href="../OEE/OEE_ChartYear.asp?cYear=[Enter Year]" target="cpOTIF_Main" >OEE 2014</a> 
And then the user enters the year they require and it is passed in the url.

Any ideas would be much appreciated

Regards
Paul

Regards

Paul

RE: passing an input variable to a querystring

Use GET instead of POST for the form.

Most users don't know the address bar from the search box, so you have absolutely no chance of them figuring out what [Enter Year] means in something they don't even notice.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum

RE: passing an input variable to a querystring

It's not the tidiest solution but you could achieve something similar in Javascript.

<a class="nav" href="../OEE/OEE_ChartYear.asp?cYear=" target="cpOTIF_Main" onclick="whatYear(event,this.id);">OEE 2014</a>

CODE --> Javascript

<script type="text/javascript">
  function whatYear(e,el){
    e.preventDefault();
    e.stopPropagation();
    var MyYear=window.prompt('Please enter the required year',new Date().getFullYear());
    if (MyYear!=null){
      var url=document.getElementById(el).attributes['href'].value+MyYear;
      window.location.replace(url);
    };
  }
</script> 

Hope this helps,

~S~

RE: passing an input variable to a querystring

Apologies - I've just realised I omitted the ID attribute of the link - the link would need an ID for the function to find it...

<a id="MyReportLink" class="nav" href="../OEE/OEE_ChartYear.asp?cYear=" target="cpOTIF_Main" onclick="whatYear(event,this.id);">OEE 2014</a>

~S~

RE: passing an input variable to a querystring

(OP)
Hi sugarflux,

Sorry I have not replied sooner but I have been on holiday, I have tested your javascript and it does what I need it to do however I do have one issue and this is my fault for not mentioning it earlier.

The pages that these menus feed are in frames, this is a 2 column frame page, left frame is "cpOTIF_Menu" and the main frame is "cpOTIF_Main"

When I use your code the linked page is displaying in the left frame as opposed to the main frame.

Can you tell me how to get it to display in the correct frame or is that not possible ?

Regards

Paul

Regards

Paul

RE: passing an input variable to a querystring

Ugh :p

Sounds like you really need to write a new website not using frames!
I'm afraid I don't have any facility for testing this as I haven't used frames for many many years...

However I think you should be able to find the frame using somthing along the lines of:

CODE --> JavaScript

top.frames['framename'].location = url; 

instead of the window.location.replace part.

Hope this helps...

~S~

RE: passing an input variable to a querystring

(OP)
Hi sugarflux,

I did not build this website initially, which is our company intranet but I have been looking after it as the person who designed it left the company. I am learning as I go and will try and rebuild it without using frames once I can get my head around exactly what it all does. In the meantime I am trying to tidy certain areas up which is why I was trying to get away from lots of menu options for various years if I could.

I tried your suggestion

CODE

top.frames['framename'].location = url; 

but it does not display a page at all so it looks like I will have to stick with the multiple menu items for now.

Regards

Paul

Regards

Paul

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close