The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
Changing links by changing vars
I'm not sure if I'd need javascript or something, but I'd like to have a link on the page that would change it's value based on is put in an input box on the page in a form. I don't want a submit button as there's quite a few of these links. An example would be www.site.com/blablabh&number=x where x is what is in the input box.
*is totally stumped* ^^;;; |
#2
|
||||
|
||||
Code:
var n = ''; if(document.formname.inputname.value == 'string') { n = x; } Code:
<a href="javascript: window.location = 'url&number=' + n;">test</a> |
#3
|
|||
|
|||
Quote:
|
#4
|
|||
|
|||
Quote:
wanna explain the n, x, and 'string' parts? I've done a TINY bit of javascript before is all... also, the IF statement. Not sure how that would be helpful as I wouldn't want to do that for every possible value it could be :ermm: |
#5
|
||||
|
||||
I'm pretty new to JS myself and have done something similar to this before. The difference was I was generating my page contents dynamically instead of relying on user input. All I can suggest is there are some fantastic JS experts over at sitepointforums.com and they undoubtedly will know the solution to your problem. If I sat down for 30mins I probably could figure it out for you. But right now I'd be going around in circles.
The basics of what you want to do is run a JS function everytime the input is changed. The value of the input is passed to the function. You mentioned you only want to change the page number based on certain values that can be entered in the form. So within the function you'd use some IF statements to check if the value passed to the function is the same as one of the required inputs. Based on this you'd assign a value to another JS variable. Then using this JS variable you'd generate the link you like dynamically. It's easy really to explain how to do it, it's just a pain to write it Try over at sitepoint and if you get no luck come back and I'll have another play |
#6
|
||||
|
||||
you might want to try
var n = ''; if(document.formname.inputname.value != '') { n = document.formname.inputname.value; } which will make n equal to what's in the input box. I also think you'll need an onchange even handler on the input for this to work. I don't know much javascript, but... Code:
<script language="javascript"> function link(var_input) { if(document.formname.var_input.value != '') { return document.formname.var_input.value; } } </script> <a href="" id="link1">sdfsdf</a> <input type="text" onchange="link1.href = link(this)"> The function first checks if the input is not empty, and if it isn't it returns the value of the input. When making the link you give it a name (link1) which you will then use to identify that link. In the input field, use the onchange event handler, so when someone types something in the input box, you give link1 the value entered in the input box. |
#7
|
|||
|
|||
It doesn't really bother me much if it's empty as it would do what I want anyways. :P
*goes off to try new help things* UPDATE : Got it working with something like... Code:
<script type="text/javascript"> function change_b8() { num_8 = document.poop.b8.value; } </script> Code:
<a href="javascript: window.location = 'http://www.site.com/blah.php?do=blah&amount=' + num_8;">[Buy]</a> |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|