SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Jan 2008
    Palm Harbor, FL
    0 Post(s)
    0 Thread(s)

    Exclamation Using a JS Prompt to set a URL variable

    I have a link that, when clicked, uses JavaScript to prompt a user to enter a value. After the user enters a value and clicks OK, I want the user to be sent to another page where the value they entered is URL variable. How can I do this?

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Christchurch, New Zealand
    104 Post(s)
    4 Thread(s)
    I see the trouble. If you change the location from the anchor click vent, you can't return false back to the anchor to prevent it from going to the default location.

    The solution, change the location from a timeout function.

    Here's some test code that does the job just fine.

    Code html4strict:
    <a id="urlprompt" href="clicked.html">Click me!</a>
    Code javascript:
    document.getElementById('urlprompt').onclick = function () {
    	setTimeout(function () {
    		window.location=prompt('Enter a value:');
    	}, 100);
    	return false;
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts