Solved

Data between pages

Posted on 2000-04-27
11
178 Views
Last Modified: 2010-04-09
I want to get string data from in an input field in an html page to another html page (actually a jsp)

On 'Submit' I do some preliminary validation on the string in JavaScript.  
Next, assuming the data has been determined to be valid, I want to
go to the next page (a jsp) and access that string, where it will be used in calls to Java methods.

How can I do this?

Cannot use VB/ASP.  Need this to work with both Netscape and IE
0
Comment
Question by:jdaues
  • 4
  • 3
  • 2
  • +2
11 Comments
 
LVL 1

Expert Comment

by:Smacked
ID: 2757750
THIS code is taken from the faulding consumer site. it's copyright fluid 1999 so dont' use it in anything commercial. this code doesn't relate to your problem but it does show how to take send data through the querystring.
I'm not going to explain it so GL.

what it does at the moment is take
?location=something.htm cuts it up a bit and works out the location for a frame (if given) is something.htm

// DECLARE VARIABLES
    var strHeader;                                          // THIS IS THE STRING OF THE DOCUMENT URL
    var strStartChar;                                    // THIS IS THE START STRING FROM WHICH WE BEGIN TO LOOK FOR THE newMainFrame LOCATION STRING
      var strMainFrameLocation;                        // THIS IS THE VARIABLE WHICH HAS BEEN PROCESSED FROM THE HTTP HEADER
      var strNewMainFrame = "products/products.htm";      // THIS IS THE DEFAULT PRODUCTS PAGE LOCATION
      var strHttpHeaderString;                        // THIS IS THE HTTP HEADER STRING ie http://www.rarara.stuff 
                                                                  // IT's PROPERTY IS DETERMINED BY WHICH BROWSER IS THERE
      var strTemp;
      
      // Assign the URL of this page to a string so we can manipulate it
      if (browserName == "Netscape")
      {
            strHttpHeaderString = document.URL;
      }
      else
      {      // Internet Explorer was not allowing any string manipulation to occur to
            // strHttpHeaderString. Hours of experimentation found that adding a null
            // to the start of the string makes it process properly
            strTemp = document.location;
            strHttpHeaderString = "" + strTemp;
      }

      // find the where 'location=' starts in this document's URL
    if (version == 3.5)
      {      
            // Internet Explorer
            strStartChar = strHttpHeaderString.indexOf("?");
      }
      else
      {
            strStartChar = strHttpHeaderString.indexOf("?");
      }

      // If the text 'location=' is not in this document's URL, then the above function will return -1

      if (strStartChar != -1)
      {      
            // SO IF THERE IS INFORMATION IN THE HTTP QUERY STRING, WE GRAB IT...
            strMainFrameLocation = strHttpHeaderString.substring(strStartChar+10, strHttpHeaderString.length);
            // AND PLUG IT INTO THE MAIN PART OF THE FRAMESET.
            strNewMainFrame = "products/product_" + strMainFrameLocation;

        }
      else
      {
            strNewMainFrame = "products/products.htm";
      }

0
 

Author Comment

by:jdaues
ID: 2759562
the answer is to user request.getParameter()
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 2763818
Use the GET method in the form. and acces it by using javascript, like:

MyArray = location.search.split("=" && "?")

Now MyArray[0] will contain the nameof the first field, and MyArray[1] the value...2 will contain the next fieldname etc etc etc

0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 2

Expert Comment

by:chuckie79
ID: 2764027
on the first page do something like the following

<FORM METHOD=POST ACTION="secondpage.html" ONSUBMIT="return CheckForm()" NAME="form1">
<INPUT TYPE=TEXT NAME="name">
..
..
..
<INPUT TYPE=SUBMIT>
</FORM>

then in script section include a function CheckForm(), which funnily enough checks the form. On an error it returns false. If form is ok then return true, for example

<SCRIPT LANGUAGE="JavaScript">
<!--
      function CheckForm
      {
            if (document.form1.name.value == "")
            {
                  // Maybe pop up a dialog box telling user error
                  return false;
            }
            else
            {
                  return true;
            }
      }
-->
</SCRIPT>

if form is ok the function returns true. Information is submitted to secondpage.  This needs to read in the data, and display or process it.  I am unsure how to do this in JSP but I guess there would be an object for the data.  Maybe something like Request (as it is in ASP).

I have found that the javascript CheckForm is usually best put in the HEAD section of a page.

Good luck

chuckie79
0
 
LVL 1

Expert Comment

by:HOOKUPS
ID: 2765587
Actually you can use asp in both netscape and internet explorer since all the code is executed on the server and only outputs html to the clients computer. With asp its quite easy

myVar = Request.form("thenameoftheinputbox")

That way you can fetch variables from your form to your script :-)

hopes it helps
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 2765593
QUOTE

Cannot use VB/ASP

/QUOTE

READ FIRST, THEN ANSWER
0
 
LVL 1

Expert Comment

by:HOOKUPS
ID: 2765602
Well cj if you read the line it sounds like he ment that he couldnt use it because he thought that asp couldnt be used in netscape that why i wrote what i wrote
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 2765642
true....depends on how you read what he wrote.
0
 

Author Comment

by:jdaues
ID: 2774374
cannot use VB/ASP
period.
0
 
LVL 22

Accepted Solution

by:
CJ_S earned 100 total points
ID: 2776361
jdaues, I provided you a way to retrieve the informion you've sent. Can you use that, or do I have to make a better function for you?

function GetQS(str)
{
    Tmp = location.search.split("=");
    for(i=0;i<Tmp.length;i++)
       if(Tmp[i]==str)
          return Tmp[i++];
    return ""
}

you pass this function the name of one of the fields you had in the form, and it will return a string with the value of it.
NOTE: you have to use the GET method in the form.

CJ
0
 

Author Comment

by:jdaues
ID: 2838110
sorry for the delay

CJ_S, as stated in my previous comment, the answer to my question is to use request.getParameter()
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to make footer stick to bottom 9 36
Button and js nou working 3 19
HTML Anchor Link Problem 3 35
Html input text color the frame line 2 20
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question