...

View Full Version : Get data from JavaScript and put into a url format



dj.html
08-31-2009, 02:28 AM
//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.



<!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>

Fumigator
08-31-2009, 09:08 PM
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:



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

dj.html
09-02-2009, 02:07 PM
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



<!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.

Fumigator
09-02-2009, 05:20 PM
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 :D

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:



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

dj.html
09-06-2009, 12:07 AM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum