cancel
Showing results for 
Search instead for 
Did you mean: 

Call Server side event from javascript

chinna_babu2
Active Participant
0 Kudos

Hi

I am using JspDynpages & JSP using HTMLB for portal development.

in which i have a textbox control.

here when i type in textbox and click enter on keyboard i want to trigger the event of server side for ex:onSearchText of button and get the relavent data back.

I couldn't find any onKeyPress event for htmlb input filed.

Can any one suggest me how can I achieve it.

Thanks & Regards,

Chinna.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Check this code.


 
   <div class="field">
<hbj:label id="label_input_name" text="User Name" design="LABEL" required="TRUE" labelFor="user_id_input" />
<hbj:inputField id="userId" type="string" maxlength="100" value="" jsObjectNeeded ="true"/>
</div>
<SPAN STYLE="visibility: hidden">
<hbj:button id="Send_Button" 
text="Submit" tooltip="Send feedback"
onClick1="onSendButtonClicked" width="100">
<% myFormId.setDefaultButton(Send_Button); %>
</hbj:button>
</SPAN>
 
 

This code will invoke server side on enter key press on input field. The submit button is hideen, if required you can set it visible by changing SPAN visibility.


<input type="text" id="search">
Use HTMLB coding for input fields

onClick1 please change to onClick

Regards

Baby

chinna_babu2
Active Participant
0 Kudos

Hi Baby,

Can you please post the complete code here. I can't see the javascript and onKeyPress event calling code in the above code snippet.

Thanks

Chinna.

Former Member
0 Kudos

Hi,

If my understanding is correct, then there is no need of any javascript.( Are u doing any kind of client side validation ?) If there is any validation required, then you can use button client side action event.

You only need to invoke server action on Enter key press in inputfield? isn't

The above code will create a button(default button), so inside the form if user press enter key it will execute the event assigned to the button(in our case onSendButtonClicked).

No need to write any explicit Javascript or onkeypress event.

If additional validation required for ur case let me know.

I will check and reply

Regards

Baby

Edited by: Baby on Oct 29, 2009 3:40 PM

chinna_babu2
Active Participant
0 Kudos

Hi Baby,

You correctly understood my requirement, this is what exactly is my requirement. I don't want to do any client side validations. Just on click on enter key while the cursor is in text box, I want to trigger the button event (server side event).

I didn't try this code earlier, hence I was expecting that here will be java script code.

Now I tried your code, it is working as I expected.

Thanks a lot for the reply.

Awarded full points.

Thanks

Chinna.

Answers (3)

Answers (3)

chinna_babu2
Active Participant
0 Kudos

Issue solved with the above code.

chinna_babu2
Active Participant
0 Kudos

Hi Baby,

This code is working for me when I have single Input field and a button in an iView. I need to implement the same where I have two Input fields and two buttons corresponding two each input field.

For ex: I have an Input field where I enter User Name and press enter key to search the user names, and in second Input field I enter city and press enter key to search cities.

Please advise me how to use the above code to cope to this requirement.

Thanks

Chinna

Former Member
0 Kudos

Hi Bala,

1. Are you using same method for both search.

2. Are you displaying both buttons in the interface with corresponding labels.

The only logic implemented in the code above is , for every form element we can set one button as default button. So if a user press enter key from any element in the form, the default button event will be triggered.

So simply you may need two Form, and in each form 1 button and 1 input field. Each button will act as default button for coressponding Form.

There may be also workaround like.. using javascript and triggering event explicitly.

If you can answer to above queries, then i will check let you know.

Please check the code, i could not test this code.

======================================



<hbj:form id="myFormId" ><div class="field">
<hbj:label id="label_input_name" text="User Name" design="LABEL" required="TRUE" labelFor="user_id_input" />
<hbj:inputField id="userId" type="string" maxlength="100" value="" jsObjectNeeded ="true"/>
</div>
<SPAN STYLE="visibility: hidden">
<hbj:button id="Send_Button" 
text="Submit" tooltip="Send feedback"
onClick_="onSendButtonClicked" width="100"
design="EMPHASIZED">
<% myFormId.setDefaultButton(Send_Button); %>
</hbj:button>
</SPAN></hbj:form> 

<hbj:form id="myFormId2" ><div class="field">
<hbj:label id="label_input_name" text="City Name" design="LABEL" required="TRUE" labelFor="city_id_input" />
<hbj:inputField id="cityId" type="string" maxlength="100" value="" jsObjectNeeded ="true"/>
</div>
<SPAN STYLE="visibility: hidden">
<hbj:button id="Send_Button2" 
text="Submit" tooltip="Send feedback"
onClick_="onSendButtonClicked2" width="100"
design="EMPHASIZED">
<% myFormId2.setDefaultButton(Send_Button2); %>
</hbj:button>
</SPAN></hbj:form>

Regards

Baby

Former Member
0 Kudos

Hi,

Check this code.


 

 
 

This code will invoke server side on enter key press on input field. The submit button is hideen, if required you can set it visible by changing SPAN visibility.

<input type="text" id="search">

Use HTMLB coding for input fields

Regards

Baby