PDA

View Full Version : javascript: onclick


Alex
December 10th, 2004, 11:15
I have this function:


function e() {
var field = document.frm.ids.value;

if(field == ' ') {
window.alert('Error: Field is empty.');
}
}


and the form:

<form name='frm' action='com/delete.php' method='post'>
<input type='text' size='45' name='ids' />

<input type='submit' name='DELETE' value='DELETE' onclick='javascript: e();' />
</form>


When I press the submit button nothing happens...
Any ideas?

the_pm
December 10th, 2004, 13:13
My initial thoought is that the script is reading the space in your function - if(field == ' ') - as the string for which is it supposed to look. I would do two things. I would add value="" to the input in your HTML, and I would remove the space - if(field == '') - from the value in your if statement.

I'll bet that works!

Alex
December 10th, 2004, 13:42
Yep, it works now, thanks : )

the_pm
December 10th, 2004, 15:36
Anytime ;)