Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 15
  1. #1
    Senior Member Seldimi's Avatar
    Join Date
    Dec 2002
    Location
    Kozani, Greece
    Posts
    488
    Member #
    409
    Hm, I am searching for a way when user clicks a link, to the page link opens to fill a value in a textform, (See example below)

    Imagine u have a link here. When user clicks it, it goes to page.htm. On page.htm there is a textbox. Is there any way to be filled with a custom value when the user cliks on the link ???
    - Webmaster's Planet . Greek Vortal For Webmasters ...
    - MyPortFolio - View My Creations

  2.  

  3. #2
    JR
    JR is offline
    Senior Member JR's Avatar
    Join Date
    Nov 2002
    Location
    UK
    Posts
    4,354
    Member #
    257
    yes i will have a go at it, do you want the link on a seperate page than the textbox?
    JR

  4. #3
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    You have to pass the value for the field in the querystring. Construct your link like this:
    Code:
    <a href="page.htm?fieldName=value">
    You can do it on the server side by doing something like:
    PHP Code:
    [b]page.php:[/b]

    <input type="text" value="<?php echo $_GET['fieldName'?>">
    Obviously that's the easiest implementation, but you may not want PHP, so here's another option, using client-side only with HTML and Javascript:
    Code:
    page.htm:
    <html>
    <head>
    <script language="javascript">
        function updateFields() {
            var url = window.location.href;
            var urlPos = url.indexOf('?') + 1;
            var urlLength = url.length - urlPos;
            if (urlPos > 0) {
                url.substr(url, urlPos, urlLength);
                var values = url.split('&');
                for (var i = 0; i < values.length; i++) {
                    value = values[i].split('=');
                    try {
                        document.getElementByName(value[0]).value = value[1];
                    } catch (e) {
                        document.body.innerText += value[0] + ' ' + value[1] + ' | ';
                    }
                }
            }
        }
    </script>
    </head>
    
    <body onload="updateFields()">
        <input type="text" value="">
    </body>
    </html>

  5. #4
    JR
    JR is offline
    Senior Member JR's Avatar
    Join Date
    Nov 2002
    Location
    UK
    Posts
    4,354
    Member #
    257
    right there is two ways you could do this, if that is you want the link on a seperate page.

    the first is to use the javascript document.referrer function, however i am not sure of the compatibility of this so i will explain a different method in another thread.

    This is how to do the referrer one

    Code:
    <html>
    <head>
    <script type="text/javascript">
    function linktext() (
    if (document.referrer == "http://www.yourdomain.com/filename") {document.form01.textbox01.value = "This text was generated by the link";}
    }
    </script>
    </head>
    <body onLoad="linktext()">
    <form name="form01">
    <input type="text" name="textbox01"></input>
    </form>
    </body>
    Just replace the yourdomain with your domain and the exact location of your file with the link in.
    JR

  6. #5
    JR
    JR is offline
    Senior Member JR's Avatar
    Join Date
    Nov 2002
    Location
    UK
    Posts
    4,354
    Member #
    257
    damn you transio :angry: lol
    JR

  7. #6
    JR
    JR is offline
    Senior Member JR's Avatar
    Join Date
    Nov 2002
    Location
    UK
    Posts
    4,354
    Member #
    257
    by the way webmasterplanet, i just tested that code in moz and it worked so it looks good

    and again...

    damn you transio :angry:

    JR

  8. #7
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    here's the HTML way... i fixed it up:
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    	<head>
    		<script language="javascript">
    		function updateFields() {
    			var url = window.location.href;
    			var urlPos = url.indexOf('?') + 1;
    			var urlLength = url.length - urlPos;
    			if (urlPos > 0) {
    				url = url.substr(urlPos, urlLength);
    				var values = url.split('&');
    				for (var i = 0; i < values.length; i++) {
    					value = values[i].split('=');
    					try {
    						document.getElementById(value[0]).value = value[1];
    					} catch (e) {
    					}
    				}
    			}
    		}
    		</script>
    	</head>
    	<body onload="updateFields()">
    		<input type="text" value="" name="fieldName" id="fieldName">
    		<a href="test.htm?fieldName=hello there">Test it</a>
    	</body>
    </html>

  9. #8
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    Incidentally, this will parse out all querystring values and fill them into the form dynamically (catching errors as it goes). It can be used for any form to be populated by a QueryString.

  10. #9
    JR
    JR is offline
    Senior Member JR's Avatar
    Join Date
    Nov 2002
    Location
    UK
    Posts
    4,354
    Member #
    257
    webmasterplanet, don't listen to this criminal - my way is much better
    JR

  11. #10
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    LOL :-P

    You can give JR the dollars.

    My soul is rich enough in knowing that I have helped someone :-D


Page 1 of 2 1 2 LastLast

Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 10:48 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2020 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com