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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

passing an input variable to a querystring

Status
Not open for further replies.

kiwieur

Technical User
Apr 25, 2006
200
0
0
GB
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=[highlight #EF2929][Enter Year][/highlight]" 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

 
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
 
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>

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~
 
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~
 
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

 
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:

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

instead of the window.location.replace part.

Hope this helps...

~S~
 
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

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top