469,329 Members | 1,373 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,329 developers. It's quick & easy.

Page submitting issue ..............

dmjpro
2,476 2GB
here is my code ......


[HTML]<html>
<head>
<title>Simple Test</title>
<script language = javascript>
function test()
{
if(document.all.txt.value == '')
{
alert('Blank');
return false;
}
else return true;
}
</script>
</head>
<body>
<form onsubmit = test()>
<input name = txt>
<input type = submit value = "SUBMIT">
</form>
</body>
</html>
[/HTML]

i want to stop submitting page if the text field is left blank .......

how can i do it .....

any help is most welcome .......
Feb 28 '07 #1
6 1104
acoder
16,027 Expert Mod 8TB
Do not use document.all! It is IE-only.

Use document.getElementById instead, but you must give an id to your text box to use this.

To solve your problem, just add "return" before calling test().
Feb 28 '07 #2
dmjpro
2,476 2GB
it is not clear to me ........

plz explain in details .....
Mar 1 '07 #3
dmjpro
2,476 2GB
sorry i think i don't understand ur point of view ......

finally i managed to do that ....

here is my code .......


<input type = submit vlaue = "SUBMIT" onclick = "if(document.all.txt.value == ''){alert('Blank');return false;}">

it's lead me to new direciton of js event overriding ......

thanx , thanxxxxx a looootttttttttttttttttttttttttttt................. ...
Mar 1 '07 #4
acoder
16,027 Expert Mod 8TB
No, don't do that! I've modified your code below:
[HTML]<html>
<head>
<title>Simple Test</title>
<script language = javascript>
function test()
{
if(document.getElementById("txt").value == '')
{
alert('Blank');
return false;
}
else return true;
}
</script>
</head>
<body>
<form onsubmit = "return test();">
<input type=text name = txt id="txt">
<input type = submit value = "SUBMIT">
</form>
</body>
</html>
[/HTML]
Mar 1 '07 #5
dmjpro
2,476 2GB
is there any special difference between ur code and my code !!!!!!!!!!!!!!!!!!!!!!!!!!

i think it is easy to code ... nothing else ... am i right .........


lot of tahnx ......
Mar 1 '07 #6
acoder
16,027 Expert Mod 8TB
No, document.all works in IE and is not standard (even though Opera supports it I think). document.getElementById is the standard and works in all modern browsers.

You could also use the name of the form to get access to the text input.

When you have onsubmit, why use the onclick for the submit? What if the form is submitted in some other way, e.g. using the submit() method?
Mar 1 '07 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

10 posts views Thread by amit.purohit | last post: by
8 posts views Thread by John Scott | last post: by
8 posts views Thread by -Karl | last post: by
8 posts views Thread by Ed Jay | last post: by
3 posts views Thread by William Youngman | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Purva khokhar | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.