Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8148901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:44:14+00:00 2026-06-06T14:44:14+00:00

I’m basically trying to create a url friendly query string with user input. The

  • 0

I’m basically trying to create a url friendly query string with user input. The variables replace spaces and @s and add it all together and then the function should display the url in the paragraph. This is making me feel really stupid because I know it’s something really simple I’m messing up. Please point out my mistake. And as a side note, is there a better way to do all this replacing without all the variables?

The following code should return a string similar to:
https://www.somewebsite.com/formhandler.php?&fname=gordie&address=123+main+street&email=something%40somewhere.com

<SCRIPT TYPE="TEXT/JAVASCRIPT">

var fnstr = document.getElementById("firstname").value; 
var fncutspace = fnstr.trim();
var fnrepspace = fncutspace.replace(/ /g,"+");
var fnfinal = fnrepspace.replace("@","%40");
var adstr = document.getElementById("address").value; 
var adcutspace = adstr.trim();
var adrepspace = adcutspace.replace(/ /g,"+");
var adfinal = adrepspace.replace("@","%40");
var emstr = emdocument.getElementById("firstname").value; 
var emcutspace = emstr.trim();
var emrepspace = emcutspace.replace(/ /g,"+");
var emfinal = emrepspace.replace("@","%40");
var domurl = "https://www.somewebsite.com/formhandler.php?&fname=";
var secondchunk = "&address=";
var thirdchunk = "&email=";
var url = domurl + fnfinal + secondchunk + adfinal + thirdchunk + emfinal;

function createurl() {
document.getElementById("demo").innerHTML = url;
}
</SCRIPT>

<FORM action="javascript:createurl()">
Fisrt Name:<INPUT id="firstname" TYPE="TEXT"><br>
street address:<INPUT id="address" TYPE="TEXT"><br>
email address:<INPUT id="email" TYPE="TEXT"><br>
<input type="submit" value="GO">
</FORM>

<p id="demo"></p>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T14:44:15+00:00Added an answer on June 6, 2026 at 2:44 pm

    If it’s supposed to be based on the user input, you should move the variables to be declared and set inside createurl:

    function createurl() {
        var fnstr = document.getElementById("firstname").value; 
        var fncutspace = fnstr.trim();
        var fnrepspace = fncutspace.replace(/ /g,"+");
        var fnfinal = fnrepspace.replace("@","%40");
        // etc.
        var url = domurl + fnfinal + secondchunk + adfinal + thirdchunk + emfinal;
    
        document.getElementById("demo").innerHTML = url;
    }
    

    That way they’ll be set to the current input values at the time the function is called.

    And as a side note, is there a better way to do all this replacing without all the variables?

    You can chain the method calls:

    var fnInput = document.getElementById('firstname');
    var fnfinal = fnInput.value.trim().replace(/ /g,"+").replace("@","%40");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I've got a string that has curly quotes in it. I'd like to replace
I need to clean up various Word 'smart' characters in user input, including but
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.