Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
  #1  
Old 09-04-2004, 07:52 PM
Tekton Tekton is offline
 
Join Date: Jun 2004
Location: Wisconsin
Posts: 362
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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* ^^;;;
Reply With Quote
  #2  
Old 09-04-2004, 08:00 PM
Dean C's Avatar
Dean C Dean C is offline
 
Join Date: Jan 2002
Location: England
Posts: 9,071
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Code:
var n = '';
if(document.formname.inputname.value == 'string')
{
        n = x;
}
Then write your link on the page like so:

Code:
<a href="javascript: window.location = 'url&number=' + n;">test</a>
This is untested but the basic principle behind it
Reply With Quote
  #3  
Old 09-04-2004, 08:08 PM
Tekton Tekton is offline
 
Join Date: Jun 2004
Location: Wisconsin
Posts: 362
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Dean C
Code:
var n = '';
if(document.formname.inputname.value == 'string')
{
        n = x;
}
Then write your link on the page like so:

Code:
<a href="javascript: window.location = 'url&number=' + n;">test</a>
This is untested but the basic principle behind it
*will try later tonight* thanks for the input
Reply With Quote
  #4  
Old 09-04-2004, 09:21 PM
Tekton Tekton is offline
 
Join Date: Jun 2004
Location: Wisconsin
Posts: 362
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Tekton
*will try later tonight* thanks for the input
Sorry for doublepost....

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:
Reply With Quote
  #5  
Old 09-04-2004, 09:38 PM
Dean C's Avatar
Dean C Dean C is offline
 
Join Date: Jan 2002
Location: England
Posts: 9,071
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #6  
Old 09-04-2004, 09:39 PM
rake's Avatar
rake rake is offline
 
Join Date: Nov 2002
Posts: 311
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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)">
Like Dean said, it's the basic principle. I don't expect the code to work. I don't know the objects/properties/methods to use. Perhaps someone with a bit more javascript knowlege can help.

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.
Reply With Quote
  #7  
Old 09-04-2004, 09:51 PM
Tekton Tekton is offline
 
Join Date: Jun 2004
Location: Wisconsin
Posts: 362
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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>
and
Code:
 
<a href="javascript: window.location = 'http://www.site.com/blah.php?do=blah&amount=' + num_8;">[Buy]</a>
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 06:10 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04127 seconds
  • Memory Usage 2,222KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (7)bbcode_code
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (7)post_thanks_box
  • (7)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (7)post_thanks_postbit_info
  • (7)postbit
  • (7)postbit_onlinestatus
  • (7)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete