Solved

Data between pages

Posted on 2000-04-27
11
175 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
 
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction The Google Maps API offers various ways to draw dynamic and static maps.  Using a combination of PHP and JavaScript, you can draw active JavaScript maps that allow pan-and-zoom in the client browser window.  You can also draw "static" …
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

757 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now