Qbasicnews.com

Full Version: How to get the value from (www.com/?this=that)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
: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:
You need a PHP or something similiar =P

Code:
<?php
echo $_GET['this'];
?>
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? :???:
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.
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
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:
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>
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...