Click to See Complete Forum and Search --> : Drop down check with text box


kiwis
02-29-2008, 01:29 PM
i have a drop down (listbox) on my form with a text box. I need a javascript to check that the value entered into my textbox is higher than the max value in my listbox?

how can I do this??? (my listbox is sorted by value so it could check the last value)

kiwis
03-01-2008, 01:58 PM
I have this code but it does not work. Why??


<script type='text/javascript'>
function checkscript() {
user_input = document.FrontPage_Form5.T3.value;
current_bid = document.FrontPage_Form5b.T1.value;

alert(current_bid);


if (user_input < current_bid) {
// something is wrong
alert('Enter a value which is higher than the current bid!');
return false;
}
return true;
}
</script>

NogDog
03-01-2008, 02:42 PM
A select list does not have a value you can directly access. You need to get the value of the selected option, instead. Assuming current_bid is the list box (change as applicable if I guessed wrong):

current_bid = document.FrontPage_Form5b.T1.options[document.FrontPage_form5b.T1.selectedIndex].value;

kiwis
03-01-2008, 07:20 PM
http://www.rugbyleaguenz.com/ERROR.JPG

I get this error however.... why?

NogDog
03-01-2008, 09:59 PM
Either a typo in my code or one in yours? ;)

"FrontPage_Form5b" should be the value of the name attribute of the <form> element. "T1" should be the value of the name attribute of the <select> element in that form. So, make sure they both match whatever values you actually used on the HTML page in question.

Weedpacket
03-02-2008, 06:08 AM
Also, try using Firefox as a development platform: its Javascript error messages actually make sense (even if you don't spring for something like Firebug).