-1

I have a JavaScript variable and I want to access it in JSP without using submit button. Actually I have a javascript variable and i want to use it for running a query in JSP to fetch a value from database and again using the value from JSP to javascript.

I do not want to have a button in the form tag for submitting the value and then getting it as a paramneter in JSP. Is there any other way of doing that.

Actually i have atextbox where username is coming. I want to use that variable so that i can run a query in JSP and find its user Id. Code for getting value of text box is.

var selUserInfo = thisFrm.SelUser.value

Now i want to pass this selUserInfo to a JSP.

4
  • Hi Sarthak, welcome to Stack Overflow. People here need to see your attempts so they can fix your code :) Commented Nov 15, 2017 at 11:11
  • Please do not ignore the "Questions that may already have your answer" list you're shown when you type that title into your question. Commented Nov 15, 2017 at 11:11
  • Hi Crowder, Please read my question first then give me your comments. Commented Nov 15, 2017 at 11:27
  • Actually if i am using a POST or GET request then i have to create a button for it. But i do not want button to be shown in UI. Commented Nov 15, 2017 at 11:30

1 Answer 1

-1

Not possible unless you send a GET or POST request. See this explanation.

Edit: after understanding that you're aiming for an autocompletion text-input, I would recommend to look for a jQuery solution like this one, and using an Ajax request to retrieve the data from your database (inside a .ready() event).

Sign up to request clarification or add additional context in comments.

7 Comments

But i dont want a button to be shown in UI. If i have to use GET or POST i have to create a button for it. Is there any way that button is not there in UI
The reference you have given will work only i hit on submit button which will be shown in UI. I dont want button to be shown
You don't have to tie the action to a button's event, you could do that to any other event, like on a value change in a text field (used for auto completion in search bars and such). Without knowing what are you aiming for it becomes more difficult suggesting a good alternative approach.
Actually i have a text box in which user name is coming. I am storing that user name is a variable in javascript and want to use that variable in JSP so that i can run a query and find the user id of it. The code for getting the value of text box is -----------var selUserInfo = thisFrm.SelUser.value. Now i want this selUserInfo variable in my JSP.
And you want to accomplish that without hitting a submit button, so with some kind of auto complete that filters all the usernames?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.