SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Jan 2008
    Location
    Palm Harbor, FL
    Posts
    348
    Mentioned
    0 Post(s)
    Tagged
    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
    Location
    Christchurch, New Zealand
    Posts
    14,684
    Mentioned
    99 Post(s)
    Tagged
    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


Bookmarks

Posting Permissions

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