Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to get the value from (www.com/?this=that)
#1
:lol: I noticed that allot, and when doing this:

Code:
<form action="Webpage.html">
<input type="text" name="this">
<input type="submit" value="Hit Me!">
</form>

The output on the browser would be simular.... How do I use that value after I hit the Submit button to controll event on the next page? I know JS is most likely involved, and I know a lil bit... but how?

Waits and dreads "You need PHP" :lol:
Kevin (x.t.r.GRAPHICS)

[Image: 11895-r.png]
Reply
#2
You need a PHP or something similiar =P

Code:
<?php
echo $_GET['this'];
?>
[Image: sig.php]
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Reply
#3
Cry Why did I know it..........

How come something a HTML code made, needs another code to get it.... There is no JS code that does the same? :???:
Kevin (x.t.r.GRAPHICS)

[Image: 11895-r.png]
Reply
#4
No, though I think you can use JavaScript to set cookies (which I have no clue how to do) with the data. Then call the cookie (JavaScript) from another Webpage and use JavaScript to do what you need.

I think HTML forms were created specifically for server interaction, usually storing the data entered into the form in a database.

I'm not exactly sure about any of this and using a server-side language such as PHP would make it a lot easier.
974277320612072617420666C61696C21 (Hexadecimal for those who don't know)
Reply
#5
You can get it easy. Here's a routine from the Code Project that splits up a URL into name/value pairs and then maps it to an associative array:

Code:
<html>
<head>
<script language="javascript">
    var urlText = window.document.URL.toString();
    var queryString = "";
    var nameValuePairs = [];
    var thisPair = [];
    var parameters = {};

    if (urlText.indexOf("?") > 0) {
        queryString = urlText.split("?")[1];
        nameValuePairs = queryString.split("&");

        for (var x=0; x<nameValuePairs.length; x++) {
            thisPair = nameValuePairs[x].split("=");
            if (thisPair[0] != "") {
                parameters[thisPair[0]] = thisPair[1];
            }
        }
    }
</script>
</head>
<body>

<script>
    alert(parameters["x"])
</script>

</body>
</html>
But remember this only applies for parameters in the url. That means you have include
Code:
method="get"
in your form tag
Reply
#6
Hmm.... doesn't seem to work.. ? I get undifined in the alert box.... Here is the code in my first file:

Code:
<html>
<head></head>

<body>
<form method="post" action="test2.html">
    <input type="text" name="test">
    <input type="submit" value="Submit">
</from>
</body>
</html>

Did I screw something up? :lol:
Kevin (x.t.r.GRAPHICS)

[Image: 11895-r.png]
Reply
#7
Unless I'm mistaken Jofers meant GET not POST.

POST are the hidden vars.
GET are the ones in the URL.

Code:
<html>
<head></head>

<body>
<form method="get" action="test2.html">
    <input type="text" name="test">
    <input type="submit" value="Submit">
</from>
</body>
</html>
[Image: sig.php]
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Reply
#8
No good,.. Tho, I did notice when experamenting more with the code, that

Code:
var urlText = window.document.URL.toString();

Doesn't get the whole URL,.. thus, if:

www.com?this=that

urlText would = www.com


???? Tongue That would mess up the parser for sure...
Kevin (x.t.r.GRAPHICS)

[Image: 11895-r.png]
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)