How to parse URL string to alphanumeric id text box?

Posted on 2005-04-29
Last Modified: 2012-05-05
I have this URL:

and i want to parse the name string into this text box without changing the name or id of the text box.

<input name="00N20000000jwkD" id="00N20000000jwkD" type="text" size=20 maxlength=15 value="">

I already have the getValue function below, but I can't seem to find a way to parse it into the text box:

function getValue(varname)
  // First, we load the URL into a variable
  var url = window.location.href;

  // Next, split the url by the ?
  var qparts = url.split("?");

  // Check that there is a querystring, return "" if not
  if (qparts.length == 0)
    return "";

  // Then find the querystring, everything after the ?
  var query = qparts[1];

  // Split the query string into variables (separates by &s)
  var vars = query.split("&");

  // Initialize the value with "" as default
  var value = "";

  // Iterate through vars, checking each one for varname
  for (i=0;i<vars.length;i++)
    // Split the variable by =, which splits name and value
    var parts = vars[i].split("=");
    // Check if the correct variable
    if (parts[0] == varname)
      // Load value into variable
      value = parts[1];

      // End the loop
  // Convert escape code
  value = unescape(value);

  // Convert "+"s to " "s
  value.replace(/\+/g," ");

  // Return the value
  return value;
Question by:misterys
    LVL 32

    Accepted Solution


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "">
        <style type="text/css">
        <script type="text/javascript">
        function getValue(varname){
            var urlArray ='&');    // Split into parts
            for(var no=0;no<urlArray.length;no++){    // Loop through variables
                parts = urlArray[no].split('=');    // Extract name and value
                parts[0] = parts[0].replace(/\W/g,'');    // remove non alpha characters from name
                if(parts[0]==varname){ // Match
                    return parts[1];    

    <form name="myForm">
    <input name="00N20000000jwkD" id="00N20000000jwkD" type="text" size=20 maxlength=15 value="">
    <script type="text/javascript">
    document.getElementById('00N20000000jwkD').value = getValue('name');

    LVL 6

    Expert Comment

    Hi misterys,

    DOM method:
    <button onclick="document.getElementById('00N20000000jwkD').value=getValue('name')">

    Another method:
    <button onclick="document.all['00N20000000jwkD'].value=getValue('name')">

    German Rumm.

    Author Comment

    Awesome, thanks guys... Batalf - works like a dream, perfect.
    LVL 32

    Expert Comment

    Glad I could help!


    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Suggested Solutions

    A common challenge, or question, when working with two calendar dates is: What is the difference between the specified days? As is frequently the case, the answer is: It depends... What kind of difference do you want? Given two date obje…
    When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (, typical array handling might look like this: (CODE) B…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now