JavaScript Help
- Started
- Last post
- 8 Responses
- kodap
OK. I have a javascript that validates the content or non-content of certain fields of a form. in this field I have inputs and textarea as well as a list menu (select) with three options
So the input felds can be filled correctly by the user, I have this condition to force the users to fill correctly the inputs/textareas:
(it's just a fraction of the script):
------ ------ ------ ------ ------
function validateform()
if (d.name.value == "" || d.name.value == null || document.formname.name.value...
{
alert("Please specify bla bla bla");
d.name.focus();
return false;
}
------ ------ ------ ------ ------
SO far so good, it works.But now, how do I make an alert specifying that the user has to select any of the items on a list (select)tag instead of the initial value of that list (on wich I have written "choose", in case he forgets to choose one of the items of the list and proceeds to the form submission?
/sidenote: everything is working allright on the Javascript, on submit it calls the JScript,
I just need to add the condition to the script for the list selections
Any help will be kindly appreciated
- honda0
don't have time to write anything and i apologize, but go here:
enter the general jist of your question. you should be able to find something there. good luck.
- kodap0
thanks H
- gabriel_pc0
I would just check to see if the selectedIndex of the field is anything other than 0. As long as the CHOOSE option is first, that should work for you.
- kodap0
I just want to add something like this to the code.. it's simple:
gereric talking:
if (initially_selected_value) alert: to choose one of the other values (items of the list)
something in code that may equal this..
- kodap0
I tried to paste one of the conditions related to one of the inputs already by giving the name of the select tag, but the script screw up the select list and re-wrote the list it in plain html.. so there must be another string I have to add in order the script function to recognize the (first option) nested in the (select tag)
or am I wrong and this is impossible?
- kodap0
IS there any developers forum out there where I can ask for help?
- mitsu0
simple, just check the selected index property of the listbox to make sure the value (index) you don't want selected isn't.
example:
select tag:
onchange='selchange(this)'script header:
function selchange(obj)
{
if(obj.selectedIndex==0)
{
alert("Invalid selection.");
}
}
- kodap0
That's it, Mitsu, You Rock!!