•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 426,187 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,852 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 885 | Replies: 4
![]() |
here you go
obviously it will work the same with a textarea but i just ripped it out of some of my own code. hope this helps
<script type='text/javascript'>
function isEmpty(elem, errMsg){
if(elem.value.length == 0){
alert(errMsg);
elem.focus();
return true;
}
return false;
}
</script>
<form>
Name : <input type='text' id='name'/>
<input type='button'
onclick="isEmpty(document.getElementById('name'), 'Please Enter a Value')"
value='Check Field' />
</form>obviously it will work the same with a textarea but i just ripped it out of some of my own code. hope this helps
When Autumn Falls [ http://www.whenautumnfalls.co.uk ] &&
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
•
•
Join Date: Jul 2006
Location: Deptford, London
Posts: 963
Reputation:
Rep Power: 5
Solved Threads: 48
•
•
•
•
Originally Posted by Fungus1487
<input type='button' onclick="isEmpty(document.getElementById('name'), 'Please Enter a Value')" value='Check Field' />
that won't validate on submit, it'll validate, but not submit. if you want to validate, you have to conditionally stop the submit, which is done by returning false within an onsubmit event. the function is right, but the call to it is not making full use of its potential.
keeping your function Fungus1487; try:
[incorrect]
EDIT:
I tell a lie! onsubmit is a form event not a submit button event:
<form action="anactionhandler.cgi" method="GET" onsubmit="return ! isEmpty(document.getElementById('name'),
'Please Enter a Value')">
Name : <input type='text' id='name'/>
<input type='submit' value='Submit!' />
</form> Last edited by MattEvans : Apr 30th, 2007 at 6:53 am.
If it only works in Internet Explorer; it doesn't work.
sorry, my mistake
When Autumn Falls [ http://www.whenautumnfalls.co.uk ] &&
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
![]() |
•
•
•
•
•
•
•
•
DaniWeb JavaScript / DHTML / AJAX Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- .net validation/javascript conflict (ASP.NET)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Java Script codes
- Next Thread: Hai All, Can anybody solve this problem its urgent


Linear Mode