Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

document.write variables

Posted on 2009-07-02
9
Medium Priority
?
289 Views
Last Modified: 2012-05-07
I want to take variables passed in URL string and write them to the body of the html page.

See code below.

What am I missing?
<html><head><script type="text/javascript" language="javascript">
 
function parseQString() {
  var qs = new Array();
  var loc = location.search;
  if (loc) {
    loc = loc.substring(1); 
    var parms = loc.split('&');
    for (var i = 0; i < parms.length; i++) {
      nameValue = parms[i].split('=');
      qs[nameValue[0]] = (nameValue.length == 2) ? unescape(nameValue[1]).replace(/\+/g,' '): null;
    }
  }
  return qs;
}
function getQSParm(parm) {
  return (qs[parm]) ? qs[parm] : null
}
var qs = parseQString(); 
 
var Contact0FirtName = "Contact0FirstName"
 
function writetext() {
   document.Contact0FirstName.value=getQSParm("Contact0FirstName");
  }
window.onload=function() {writetext();}
 
</script><body><SCRIPT LANGUAGE=JavaScript>
document.write("Contact0FirstName!");
</SCRIPT>

Open in new window

0
Comment
Question by:3rdLifeWebDev
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24762592
several issues

Here is a better one

<html><head>
<script type="text/javascript" language="javascript">
 
function parseQString() {
  var qs = new Array();
  var loc = location.search;
  if (loc) {
    loc = loc.substring(1); 
    var parms = loc.split('&');
    for (var i = 0; i < parms.length; i++) {
      nameValue = parms[i].split('=');
      qs[nameValue[0]] = (nameValue.length == 2) ? unescape(nameValue[1]).replace(/\+/g,' '): null;
    }
  }
  return qs;
}
function getQSParm(parm) {
  return (qs[parm]) ? qs[parm] : "Not Passed"
}
var qs = parseQString(); 
 
function writetext() {
   document.forms[0].Contact0FirstName.value=getQSParm("Contact0FirstName");
  }
window.onload=function() {writetext();}
 
</script><body><SCRIPT LANGUAGE=JavaScript>
document.write("Contact0FirstName:"+getQSParm("Contact0FirstName"));
</SCRIPT>
<form>
<input type="text" name="Contact0FirstName" value="" />
</form>

Open in new window

0
 
LVL 5

Expert Comment

by:mnialon
ID: 24762605
hello
or you can see :

http://www.netlobo.com/url_query_string_javascript.html

if you want

hope this helps
michel

0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24762667
That was not his problem
The problem was syntax AFTER getting the parameters:

1.  document.Contact0FirstName.value is not valid syntax

2. document.write("Contact0FirstName!"); only writes the string Contact0FirstName!
0
Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24762767
3. useless misspelled variable
var Contact0FirtName = "Contact0FirstName"

0
 

Author Comment

by:3rdLifeWebDev
ID: 24762979
MPlungjan,

<SCRIPT LANGUAGE=JavaScript>
document.write(getQSParm("Contact0FirstName") + '' + getQSParm("Contact0LastName"));
</SCRIPT>

I need a space between the first and last name.
0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 2000 total points
ID: 24763107
Ok - so why not put one?


document.write(getQSParm("Contact0FirstName") + ' ' + getQSParm("Contact0LastName"));

or

document.write(getQSParm("Contact0FirstName") + '&nbsp;' + getQSParm("Contact0LastName"));
 
0
 

Author Comment

by:3rdLifeWebDev
ID: 24763200
Uhh ...

THANKS!
0
 
LVL 16

Expert Comment

by:CWS (haripriya)
ID: 37296666
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
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…

705 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