DatePicker - how to keep the selected value after clicking on submit button - java

I want to keep the selected value after clicking on submit button.
Right now when i chhose value from datepicker and when i click on submit button then my textbox value become empty. I used javascript.Following is my code
<script>
$(function() {
$( "#datepicker" ).datepicker();
});
</script>
<input type="text" id="datepicker" name="<portlet:namespace/>datepicker" value=""/><br>
How can i solve this problem please help me...
Thanks!!!

If you set value="", you should expect to get the default, whatever datepicker displays. Set it to the value that you want to start with and you should be good.
Figure out the formatting that it requires, most likely it's the same one that gets transmitted as request parameter when you submit your form.

Related

Keys.RETURN and Keys.ENTER not triggering form submission

I havent been able to select the element in googles popup form that will let me submit the form so i opted to use Keys.TAB and Keys.ENTER but it doesnt trigger submission. if i do it manually it works but my code just highlights the button and presses ENTER with no success.
popup window image
driver.findElement(By.xpath(someElement)).sendKeys(Keys.TAB);
Thread.currentThread().sleep(1000);
driver.findElement(By.xpath(someElement)).sendKeys(Keys.TAB);
Thread.currentThread().sleep(1000);
driver.findElement(By.xpath(someElement)).sendKeys(Keys.ENTER);
I added a pause between each key press because i read on here that it can be an issue but it hasnt solved my problems. for perspective the form im trying to submit is the google search console URL removal confirmation and the div surrounding the button looks like this:
<div role="button" class="U26fgb O0WRkf oG5Srb C0oVfc kHssdc sZloWc M9Bg4d" jscontroller="VXdfxd" jsaction="click:cOuCgd; mousedown:UX7yZ; mouseup:lbsD7e; mouseenter:tfO1Yc; mouseleave:JywGue; focus:AHmuwe; blur:O22p3e; contextmenu:mg9Pef;touchstart:p6p2H; touchmove:FwuNnf; touchend:yfqBxc(preventMouseEvents=true|preventDefault=true); touchcancel:JMtRjd;"
jsshadow="" jsname="LgbsSe" aria-disabled="false" tabindex="0" data-id="EBS5u">
<div class="Vwe4Vb MbhUzd" jsname="ksKsZd"></div>
<div class="ZFr60d CeoRYc"></div><span jsslot="" class="CwaK9"><span class="RveJvd snByac">Submit request</span></span>
</div>
I've been racking my brain trying to access this last button, some help would be much appreciated. is there a better way to go about this? or have i missed something important in the form to allow me to access the submit button

How to identify if a radio button is checked in selenium?

I have below html code snippet for radio button .
<label for="exceptionTrue">
<span/>
<span class="check" style="background: #F3565D;"/>
<span class="box"/>
Yes
</label>
HTML displayed is the same if the radio button is selected or if not selected in the page.
Element is in span class='check' if the radio button is selected and is in span class='box if not selected.
Since the html code is present in page if the radio button is selected or not selected.So i cannot user verifying if class='check' .
.Any idea how i can verify this...I have tried is.Selected and it doesn't work
Well I don't see a problem here, you know how this radio button works and you just need to implement this verification. Find your radio button element and than:
if (element.getAttribute("class").equals("check")){
return true; }
else {
return false; }
This is just an example, you can adjust this to your code.
EDIT: When I read your question again it's really unclear so I'm not sure if this helps. You need to provide more details on this.

How to detect double click on JSP

how can I make my jsp page detect a double click on the submit button. I am trying to do a simple print out message to check if a user has double clicked the submit button.
something like :
<%***if user double clicks submit{
System.out.println("doubleClick");`
}***%>
-Newbie trying to learn java programming.
Believe me you are not looking for Java
You can simply use Javascript function
ondblclick="myFunction()"
Or you can use Jquery for this:
$( "#target" ).dblclick(function() {
alert( "Handler for .dblclick() called." );
});
Details
You can use ondblclick attribute in your button element.E.g-
<input id="searchId" type="button" ondblclick="doubleFunc()"
name="submit">
Make sure you also handle the submit event in your script.

commandLink disabled via javascript can still be clicked

I need to disable the button based on the selected row of t:dataTable.
This is the javascript method I'm calling on the row selection event
(the button should be disabled if an item in the selected row has a tooltip... it's ugly, but it was the easiest thing to do):
function processUpdateButton() {
if (!$(".selectedRow").length
|| $(".selectedRow").children().find(".tooltip").length){
$(".Update").button({disabled:true});
} else {
$(".Update").button({disabled:false});
};
}
This is the JSF commandLink:
<h:commandLink id="update" styleClass="Update iconButton"
action="#{myBB.update}"
value="#{gui['button.update']}"
tabindex="301"/>
Setting disabled attribute to the button works. The button is greyed out and if I hover the mouse over it, the cursor doesn't change as it does for other links. The problem is, that I can still click it and the method in the backing bean is called. Is there some way to prevent that?
Here's the rendered disabled button:
<a id="mainForm:update"
class="iconButton ... ui-button-disabled ui-state-disabled"
onclick="return myfaces.oam.submitForm('mainForm','mainForm:update');"
href="#" role="button" aria-disabled="true" disabled="disabled">
<span class="ui-button-text">Update</span>
</a>
I should probably remove the onClick attribute, but I don't know how I would be able to reenable it again.
Of course I can check the condition on the server after clicking the Update button, but that's the last resort. It would be nice if I could completely disable the button generated by JSF only from javascript without call to the server.
So I've found the solution. I copied the onclick attribute to another attribute on disabling button and vice versa:
var onclick;
if (!$(".selectedRow").length
|| $(".selectedRow").children().find(".tooltip").length){
$(".Update").button({disabled:true});
onclick=$(".Update").attr('onclick');
$(".Update").attr('onclick2',onclick);
$(".Update").removeAttr('onclick');
} else {
$(".Update").button({disabled:false});
onclick=$(".Update").attr('onclick2');
$(".Update").attr('onclick',onclick);
$(".Update").removeAttr('onclick2');
};
As you can see the generated html code is not a button but hyperlink. So you need to remove the link from link tag. Could try follows:
$(".Update").removeAttr('href');

Why i can't use request.getParameter in my form

i have a question about using request.getParameter(), i knew that it can use to post the value using request.getParameter, Is it necessary match request.getParameter and <input>???
My original code in HTML:
<INPUT type=submit name="submit" value="download">
In JSP:
String start = request.getParameter("submit");
Now I want to change a button and use div
div name="submit"id="submit" class="btnStyleFunc"
onclick="document.body.style.cursor='wait';this.disabled='true';
document.getElementById('form').submit();">
But it doesn't work, anyone can help me ?
Now i use the method below, but another problem is raised...the action does not stop...
String start = request.getParameter("submit1");
<input type=hidden name=submit1 value=download>
<div class="btnStyleFunc" onclick="document.body.style.cursor='wait';
this.disabled='true';document.getElementById('form').submit();">
Does anyone know what the problem is ?
A clicked submit button is a successful form control and its name/value pair will be submitted to the server in the form data.
If you submit a form with JavaScript, there is no clicked submit button, so it won't appear in the data. A div cannot have a name and is not a form control anyway — it isn't a submit button, even if it triggers JavaScript that submits the form.
Using a div with JavaScript also breaks the form for:
Anyone not using a mouse/trackpad/etc to navigate the page (a div won't get the focus when tabbing through interactive elements)
Anyone with JavaScript disabled
Anyone using a screen reader in forms mode (div elements are not form controls).
Use a real submit button instead.

Categories

Resources