www.webdeveloper.com
Results 1 to 2 of 2

Thread: url vars going to html form

  1. #1
    Join Date
    Aug 2010
    Posts
    3

    url vars going to html form

    i decided to get fancy with this code from fang and fell on my face. i have repeated this code(which works btw) and changed the ('field_') bit and it reads the first and third but not the second var why?
    some.html?f=1&d=2&c=3
    if i cahange the substring to correspond to the var to (2) it reads f and d
    if i add the third one calling substring (3) it wont read (2) but reads 1 and 3
    any suggestions.

    <SCRIPT type=text/javascript>
    window.onload=function() {
    var data=location.search;
    if(data) {
    data=location.search.substring(1); // remove the '?'
    data=data.split('&');
    var pairs={};
    for(var i=0; i<data.length; i++){
    var tmp=data[i].split('=');
    pairs[tmp[0]]=tmp[1];
    }
    document.getElementById('field_1').value = tmp[1];
    }
    };
    </SCRIPT>

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Code:
    document.getElementById('field_1').innerHTML = pairs['f']+", "+pairs['d']+", "+pairs['c'];

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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