• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 296
  • Last Modified:

How to parse URL string to alphanumeric id text box?

I have this URL:

http://www.traveltradeonly.com/acsmatch.htm?name=00120000000nm6a

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
      break;
    }
  }
 
  // Convert escape code
  value = unescape(value);

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

  // Return the value
  return value;
}
0
misterys
Asked:
misterys
  • 2
1 Solution
 
BatalfCommented:
Example:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
     <title>Test</title>
    <style type="text/css">
    body{
        width:100%;
        height:100%;
        padding:0px;
        margin:0px;
    }
    </style>
    <script type="text/javascript">
    function getValue(varname){
        var urlArray = location.search.split('&');    // 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];    
            }            
        }    
    }    

    </script>
</head>
<body>
<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');
</script>

</form>
</body>
</html>  
0
 
German_RummCommented:
Hi misterys,

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

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

---
German Rumm.
0
 
misterysAuthor Commented:
Awesome, thanks guys... Batalf - works like a dream, perfect.
0
 
BatalfCommented:
Glad I could help!

Batalf
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now