• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Strange - Page Submits!!!

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am developing a simple web application. It doesn't have any database connections. Just simple page flows. In all the pages, I am calling a javascript function which validates for the empty or null values of the form fields, and then submits if everything is proper. The problem I am facing is, all the pages which contain a single textbox in the form, gets submitted before the javascript function is processed. Though the javascript function gets called on click of the button, the page gets submitted in the background. But this does not happen in other pages which contain more than one textbox though the function and logic is the same everywhere. Can anyone tell me what could be the problem.

Thanks in advance.

 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Tiger",

We're pleased to have you here with us on the Ranch, but there are a few rules that need to be followed, and one is that proper names are required. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
Forum Bartender
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And since this really has nothing to do with JSP, I'm moving it along to the HTML/Javascript forum.
 
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Tiger,

Can you tell, where are you actually submiting the form? Are u doing it by specifying the form action="/servlet/or something" in the form or submitting it explicitly using the Javascript?

Also check this...are the buttons are the type submit or button?

If it is submit, try changing it to button and then try submitting the form.

Cheers,
Swamy
 
Naani Mui
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am submitting the form from the javascript function. Only one function in my javascript file contains the submit function call.

Also I am not using any buttons in the form. It contains an image.

WHy I find it strange is, the page works fine on click of the image - it calls the validation functions and if everything is proper, then submits the page. But when I press enter, the page gets submitted without calling any of the javascript functions. I am capturing the key events on the document and if the key pressed is "Enter" I am calling the validation function. The validation function returns true if the form field is NOT NULL. Returns false if it is empty. If true is returned, the page should get submitted. If false is returned, the page should NOT get submitted and it should return focus to the respective form field.
This is not happening on enter press.

The same page works fine when I click on the image for submitting the page.

When I press "Enter" though the validation function is called, the page gets submitted in the background which I can see while the alert is displayed.

All these things happen only if the page contains a single text box. If it has more than one textbox, everything works fine - ALL THE FUNCTIONS AND LOGIC IS THE SAME IN ALL PAGES - ALL THE JAVASCRIPT FUNCTIONS ARE IN A SINGLE JS FILE.





Please help..
 
author and deputy
Posts: 3150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Java Rani,
Like Bear Bibeault said please change your display name.

We will try to help you with your quesitons.
 
Ramaswamy Srinivasan
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can u give the code?

Cheers,
Swamy
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The default property of a form with a check box is to submit when the enter key is pressed. It sounds like you are doing your validation wrong.

Use the onsubmit property of the form tag to do your validation code.

Eric
 
Naani Mui
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But, I am using a TEXT box. Not a Check Box.
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the 'name' of your submit button? You didn't call it 'submit', did you? If you did, try making sure no elements are called 'submit', rename them 'btnSubmit' or something.

Dave
 
Naani Mui
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
html:form name="DummyForm" type="org.apache.struts.action.DynaActionForm"action="/feedback"


INPUT TYPE=TEXT NAME="tb1" VALUE="" MAXLENGTH=7 SIZE=7

A href="javascript:fnFeedBack('x','y','z')"
img src="images/update.gif" ALIGN=TOP width="97" height="26" border="0"
/A


script Language="JavaScript"
var thisForm = document.DummyForm;
isFullyLoaded = true;

var tb1 = thisForm.tb1;

function checkForm()
{
var fieldHandle = thisForm.tb1;
var fieldValue = fieldHandle.value;
if (!isInteger(fieldValue))
{
//return sendErrorMessage(fieldHandle, getisIntegerErrorMessage());
}
if (isEmpty(tbQuestion_1.value) || (tbQuestion_1.value < 0))
{
alert("Please enter a whole number of 0 or greater.");
getFocus(tbQuestion_1);
return false;
}
return true;
}
function isEmpty(s)
{
for (i = 0; i < s.length; i++)
{
if (s.charAt(i) != " ")
return false;
}
return true;
}
function isInteger(s) {

if (isNaN(s) || isNaN(parseInt(s)) || (parseInt(s) != parseFloat(s)) || (s.indexOf(".") >= 0) )
{
if (!isEmpty(trim(s)))
{
return false;
}
else
{
return true;
}
}
else
{
return true;
}
}
function fnFeedBack(a,b,c)
{
if(checkForm())
{
fnSubmit(a,b,c);
}
}
function fnSubmit(aa,bb,cc)
{
thisForm.submit();
}
var isNav, isIE;
document.keyup = checkChar;
function checkChar(evt)
{
var Key;
if (isNav)
{
Key = evt.which;
}
else
{
Key = window.event.keyCode;
}

if(Key == 13)
{
if (isIE)
{
fnEnterPressed();
}
else
{
isNavEnterHit = true;
}
}
}
function fnEnterPressed()
{
fnFeedBack('x','y','z');
}
/script
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i meant text box, not sure why I typed check...
 
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not sure, if this is the issue, but:
Since the form contains only 1 element, which is text, and you dont have any handler for onsubmit in a form tag, form will get submitted, if user hits "Enter".
You should handle keydown opose to keyup.
[ October 05, 2004: Message edited by: Yuriy Fuksenko ]
 
Naani Mui
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
THANKS A LOT. I WAS ABLE TO FIX THE PROBLEM BY ADDING SOME JAVASCRIPT IN THE FORM ONSUBMIT EVENT.

THANKS ONCE AGAIN.

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic