Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Aug 2009
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Get data from JavaScript and put into a url format

    //CODE REMOVED

    JS Code has been removed for this example as what I would like to do is not needed.

    The data passes thru the browser, What I need is to grab the data into some kind of varable and then goes to a link/button.

    Example:

    site.com/js.php?name=NAME&number=555555&address=1 Demo Drive&email=demo@site.com

    The PHP part I can code.

    I need the data that parses thru JavaScript to be put into the above URL:

    site.com/js.php?name=+ p.Name +&number=+ p.Number +&address=+ p.Address +&email=+ p.Email +

    Then that variable passes thru a link or button.

    The way the system is system is the reason why I have 2 for(s) and cannot be changed.

    Code:
    <!DOCTYPE  HTML  PUBLIC  "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head>
    <script id="Example" language="javascript">
    <!--
    function example() {
    
          //CODE REMOVED
    
          for (;!example.atEnd();example.moveNext ())
          {
                var p = example.item ();
                document.write("Name: " + p.Name + "<br />");
                document.write("Number: " + p.Number  + "<br />");
                document.write("Address: " + p.Address  + "<br />");
          }
    
          for (;!example1.atEnd();example1.moveNext ())
          {
                var p = example1.item ();
                document.write("Email: " + p.Email + "<br />");
          }
    
    }
    //-->
    </script>
    </head>
    <body onload="example()"></body>
    </html>

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Posting this in the Javascript Frameworks forum, did you want a Framework (ie. jQuery or Mootools or Prototype) solution? It's quite simple to change a tag's attribute, ie, the "href" attribute of an <a> tag. In jQuery you do:

    Code:
    //In this case your <a> tag  has an id of "thelink".
    $("#thelink").attr({href: "js.php?name=" + nameVar + "&number=" + numberVar});

  • #3
    New to the CF scene
    Join Date
    Aug 2009
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry, Didn't realize this was the framework room;

    Do you know how some coders, Code at night and their code is bugy? and Commercial Scripts needs updating, Well posting in the wrong thread can do that too you as well. Lol

    Anyway, I've added this:

    $("#thelink").attr({href: "js.php?name=" + nameVar + "&number=" + numberVar});

    to

    Code:
    <!DOCTYPE  HTML  PUBLIC  "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head>
    <script id="Example" language="javascript">
    <!--
    function example() {
    
          //CODE REMOVED
    
          for (;!example.atEnd();example.moveNext ())
          {
                var p = example.item ();
                document.write("Name: " + p.Name + "<br />");
                document.write("Number: " + p.Number  + "<br />");
                document.write("Address: " + p.Address  + "<br />");
          }
    
          for (;!example1.atEnd();example1.moveNext ())
          {
                var p = example1.item ();
                document.write("Email: " + p.Email + "<br />");
          }
    
          $("#thelink").attr({href: "js.php?name=" + p.Name + "&number=" + p.Number + "&address=+ p.Address  + "&email=" + p.Email});
    
    }
    //-->
    </script>
    </head>
    <body onload="example()"></body>
    <a id="thelink">The Link</a>
    </html>
    The link shows, but after you hover over it, does not show the varablies, therefore either I'm doing something wrong or doesn't work.

    The orginal code uses an ActiveX Control and once you press "Yes" to allow access too it, 'The Link' URL no longer works.

    Therefore, Since the data is processed after ActiveX Control it cannot grab the varibles and process it through the link.

  • #4
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Yeah I know how that can happen... late at night or in the middle of the day, doesn't seem to make a difference in my case

    Anyway, my code is jQuery so you'd have to include the jQuery library in your page for that to work. Just using Javascript you can set the href attribute of an <a> tag like this:

    Code:
    //your <a> tag has an id of "thelink"
    document.getElementById("thelink").href="js.php?name=" + nameVar + "&number=" + numberVar;

  • #5
    New to the CF scene
    Join Date
    Aug 2009
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yeah, It's still not working.

    Adding <a id="thelink">The Link</a> below body, Shows the link but not varabiles.

    Adding <body id="thelink" onload="example()"> doesn't appear at all.

    Maybe I need to explain this better,

    The JS uses an ActiveX Control (Part of the Code removed) to get data of the Computer (Like PC Pitstop) it detects your computer information in a browser. (Locally)

    Once it does that, I need a link that you can click on with the vars that submits the data from the computer information that is displayed to be sent into my PHP Script I created and that inserts into a MySQL DB and then redirects with an ?id=idnumber.

    I'm making a CPU-Z like script instread he uses an executable, I've created one thru an Visual Basic, It works, but also has a lot of bugs; I figure HTML/JS is the best way to go once I figure it out.

    Unless you know of an ActiveX Control that does everything like that point me in the right direction; On the other hand I'm writing it from scratch, but few bumps.


  •  

    Posting Permissions

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