0

Hi everyone!
I am tyring to design two pages with Jscript and HTML.It's is really simple but I have problem:)
on first page,you write your first name and family and by you clicking on submit button you will be directed to another web page that Welcome you.
I konw I should use querystring.
This code is for first page.

<!DOCTYPE html>
<html>
<body>
<form id="frm1" action="HW1.html" method="post" target="_blank">
  First name: <input type="text" name="fname"><br>
  Last name: <input type="text" name="lname"><br>
  <input type="Submit" value="Enter">
</form>

<script>
document.write(document.getElementById("frm1").method);
</script>

<p>Click to see welcome message</p>

</body>
</html>

I try this for something like this for the second one.(HW1.html)

<!DOCTYPE html>
<html>
<head>
 <script>
function welcome(fname,lname)
{
 alert("Welcome "   +fname +" "  +lname);
 }
</script>


 <script>
 function func()
   {
    var fname= Request.QueryString("fname");
    var lname= Request.QueryString("lname"); 
     welcome(a,b);
     }
</script>
</head>
<body>
alert(func());

</body>
</html> 

It's better if I don't use alert.

and another try:

<script>
document.write("<p> welcome <%=Request.QueryString("fname")%>. 
 <%= Request.QueryString("lname")%> </p>");
</script>

<script type="text/javascript">
alert('Welcome <%=Request.QueryString("fname")%> <%= Request.QueryString("lname")%>');
</script>

anyway I really don't know how to show the names in second page correctly...

Edited by shotokanpoloto

3
Contributors
5
Replies
6
Views
4 Years
Discussion Span
Last Post by shotokanpoloto
0

Using the QueryString varible can open your site for security risks. I would use PHP instead of JavaScript because people sometimes disable JavaScript and your page may malfunction.

0

On the first page, you are submitting a form via POST so you are not passing the values via a query string.

On the receiving page, you need some server-side scripting to gather the values you posted. Since you are not passing the values via GET in the query string, there isnt anything for you to retreive.

Are you using ASP, or ASP.NET for your server side scripting?

It doesnt sound like you are too sure, did you just copy and paste this code from somewhere?

0

I just try to find some samples and mix them so that I may get answer:(
No I'm just using Jscript.
I try GET too but it wasn't useful.
anyway I'm just a beginner and now really confused:(

0

You can gather the query string paramters on the client side using JavaScript or JQuery. There are plenty of examples on line. However, keep in mind that you will be using that data client side.

If you needed to use the query string parameters for example to do a lookup in a database, you would typically handle that server-side.

0

It seems this one works

<html>
<body>
<script>
     var urlParams = {}; 
     var match, 
     pl     = /\+/g,  
     search = /([^&=]+)=?([^&]*)/g,       
     decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); },  
     query  = window.location.search.substring(1);   
     while (match = search.exec(query))      
        urlParams[decode(match[1])] = decode(match[2]); 
     alert("hello " + urlParams["firstname"] + " " + urlParams["lastname"]);
</script> 
</body>
</html>




<html>
<body>
    <form method="get" action="p2.html">
        First Name:
        <input type="text" name="firstname"><br />
        Last Name:
        <input type="text" name="lastname">
        <br />
        <input type="submit" name="Ok">
    </form>
</body>
</html>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.