Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP sending and recieving data from html

 
Tempora Telora
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I completely forgot how to set the hidden variables and be able to pass it to another jsp..

I know i need to create a function ie sumbitClick ( argument, argument)
but i dont know what to do inside the function


For example i have FName and LName as the fields for input and i have LastName and FirstName has hidden variables to be passed..

How do i set LastName and FirstName and be able to pass it to another jsp.


Once I get it over i know i just do like <% firstName = FirstName %> or something like that? Maybe not?

Thank you,
Randy
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you getting from one JSP to the other? Form submission?

If so, and as you state:

For example i have FName and LName as the fields for input and i have LastName and FirstName has hidden variables to be passed..


you already have form fields with the data, why do you need to copy the same data to hidden fields?
[ June 01, 2006: Message edited by: Bear Bibeault ]
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If FName and LName are already input fields (<input type="text"> ,
you don't need to put their value into hidden fields.
If there are contained in your form, they will be sent when you submit the form.

For example:

No need to use hidden fields. You can retrieve the values in secondJsp.jsp, with EL : ${fname} and ${lname}.
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Satou kurinosuke:
You can retrieve the values in secondJsp.jsp, with EL : ${fname} and ${lname}.


I think, ${fname} would return (write in out) something only if any scope has attribute with name 'fname'. But here, fname is parameter.

Am I right?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you are right. The parameters will be available from the builtin param scoped vairable.
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:
Yes, you are right. The parameters will be available from the builtin param scoped vairable.


like,

${param.fname}

 
Tempora Telora
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an input field name of lname and value of lastname. Lastname is initialized to "". I want once the user clicks the submit button i need to send that data to the function so i can set my hidden and then go to the new form..

I am using forms. The name of hte form is myform. In my function i have document.myform.LastName.value = passed variable.

the only problem is that my passed variable is always null.

here is what i have

on
click = " sumbit('<%= lastname%>')"

it will always send nothing though

any ideas?

Thank you,
Randy
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your language is very imprecise so it's not entirely clear what you are asking or trying to do. Let me try to clarify things. Please be sure to answer any questions that I ask in this reply or we cannot help you.

Originally posted by Randy Tatham:
I have an input field name of lname and value of lastname.


So lname is <input type="text" name="lname">.

A "value of lastname" doesn't tell us anything. I'm assuming from later code snippets that you mean a JSP scripting variable named lastname?

Lastname is initialized to "".


Where and how?

I want once the user clicks the submit button i need to send that data to the function


What is "that data" and what function?

I am using forms. The name of hte form is myform. In my function i have document.myform.LastName.value = passed variable.


What is "LastName"? You haven't mentioned it before? Did you mean the "lname" field?

here is what i have

on
click = " sumbit('<%= lastname%>')"


What is "submit"? A function you defined?

it will always send nothing though


If "lastname" is a scripting vairable that contains the empty string, then why are you surprised that <%= lastname %> evaluates to the empty string?
[ June 02, 2006: Message edited by: Bear Bibeault ]
 
Tempora Telora
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok lets try this again.....

Tell me if i get this even close to being right.

I have an input field. The name of the input field is lname.

I want to send lname to a function to be able to pass it to another jsp.

I have hidden variables that are being passed via the form.

I am setting the hidden variable via the input from the text field with the text in the lname text field.

ie

input= text name= lname
0nclick = submit(*pass something here*)

submit(lastname)
mydocument.blah.value = lastname
etc.


Any ideas?
[ June 02, 2006: Message edited by: Randy Tatham ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Randy Tatham:

I want to send lname to a function to be able to pass it to another jsp.


This is the question I asked at the very beginning: Why?

If you've already got the value in a text field, it will be "passed" to the JSP that the form is being submitted to. Why do you feel the need to do anything else?

You're either completely over-thinking the problem, or not conveying the reason that you feel the need to do all this copying around.
 
Tempora Telora
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are completely right. WoW i love trying to do the hardest thing possible when the easiest way is right infront of ur face.. ty for ur help
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic