![]() |
| |||||||
| Sponsored Links |
![]() |
| | LinkBack | Thread Tools | Display Modes |
|
#1
| |||
| |||
| hi, I have a textbox and i want to see the user has a value entered in it If he doesnt enter a number value then fire a alert so right now I am checking that he doesnt press the space bar and have a empty space here is my code. But its not working Code:
if(trim(document.frm1.txtnumber.value)
{
alert("enter a value");
}
function Trim(s)
{
// Remove leading spaces and carriage returns
while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
{ s = s.substring(1,s.length); }
// Remove trailing spaces and carriage returns
while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
{ s = s.substring(0,s.length-1); }
return s;
}
|
| Sponsored Links |
|
#2
| ||||
| ||||
| try this: Code: function isNumeric(elem, helperMsg){
var numericExpression = /^[0-9]+$/;
if(elem.value.match(numericExpression)){
return true;
}else{
alert(helperMsg);
elem.focus();
return false;
}
}
Last edited by Rebelle; July 2nd, 2008 at 11:19 AM. Reason: redid |
|
#3
| ||||
| ||||
| Try this:- Code: function check_no(the_id){
var patt1 = New RegExp("^[0-9]{1,9}$");
var the_value = document.getElementById(the_id).value;
alert(patt1.test(the_value));
}
To call it have something like:- Code: <input id="no_only" type="text" size="20" />
<input id="button1" value="Click" type="button" onclick="check_no('no_only');" />
|
|
#4
| |||
| |||
| hi, that works out Can you guys tell me whats wrong with this code I have a textbox if he value is blank or no value or if its $0 then i want to fire the alert I have this code Code:
var getfinallingtotal=document.frm1.total.value;
If(getfinallingtotal=="" || getfinallingtotal=="$0")
{
alert("enter something");
}
idea |
|
#5
| ||||
| ||||
| Try using document.getElementById instead, assuming you have given the textbox an id of total. Also try changing the double quotes to single. Code:
var getfinallingtotal=document.getElementById('total').value;
If(getfinallingtotal==''||getfinallingtotal=='$0')
{
alert('enter something');
}
|
|
#6
| |||
| |||
| i tried it doesnt work |
|
#7
| ||||
| ||||
| What do you mean "it doesn't work"? Do you get any errors? What happens? I just tried this:- Code: function check_box(){
var getfinallingtotal = document.getElementById('total').value;
if(getfinallingtotal==''||getfinallingtotal=='$0')
{
alert('enter something');
}
}
<input id="total" type="text" size="10" />
<input id="button1" type="button" value="Check" onclick="check_box();" />
|
![]() |
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| checkbox validation | todd2006 | JavaScript Programming | 3 | June 18th, 2008 07:22 PM |
| Textbox or List help | Rebelle | JavaScript Programming | 9 | April 21st, 2008 10:00 AM |
| Programmatically Add Item to Validation Summary | jmurrayhead | .Net Code Samples | 0 | March 20th, 2008 09:41 AM |