www.webdeveloper.com
Results 1 to 3 of 3

Thread: I want to display a field passed to my html

  1. #1
    Join Date
    Mar 2010
    Posts
    2

    I want to display a field passed to my html

    Say I have a url like this:

    http://www.anywebsite.com/?this_form=
    &ad_template=
    &error=The+form+required+some+values+that+you+did+not+seem+to+provide.+
    &extra=email%0A
    &errcode=missing_fields
    &isusererror=1
    &alerted=1
    &erroritem1=email
    &contact=Y
    &mesg=
    &PHPSESSID=979tuombuirucdd7q2j8bjsnn4

    I've carriage returns in there so you can read it easier.

    How do I display the passed fields on the html page?

  2. #2
    Join Date
    Mar 2010
    Posts
    2,803
    To view the name/value pairs in a query string in the target html page, you have to parse the query string after which you can then display the reults on the web page.

    This script should do what you are after:


    Code:
     
    <script type="text/javascript">
    if (window != top) top.location.href=location.href
    document.write("\<h2>You entered the following data:</h2>");
     
    var formData = location.search;
     
    formData = formData.substring(1, formData.length);
     
    while (formData.indexOf("+") != -1) {
    formData = formData.replace("+", " ");
    }
     
    formData = unescape(formData);
     
    var formArray = formData.split("&");
     
    for (var i=0; i < formArray.length; ++i) {
    document.writeln(formArray[i] + "<br />");
    }
     
    </script>

  3. #3
    Join Date
    Mar 2010
    Posts
    2
    Thanks! I was almost there, but was lacking what I needed to remove the +'s and insert spaces. You rock!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles