Jump to content

anyone?


justAnoob

Recommended Posts

sorry to post this here,, but no one is ever on the other boards...

I'm looking to put some validation on my listmenu on my page.. the validation for my textfields work great

ex.

 

<input name="item_name" type="text" id="item_name" size="50" /><span id="item_name_error" class="error"></span>   

 

if (!form1.item_name.value)

    {

        document.getElementById('item_name_error').innerHTML = 'Please enter a name.';

        valid = false;

    }

    else

    {

        document.getElementById('item_name_error').innerHTML = '';

    }

 

 

 

thats works perfectly

 

now how would i go about adding the span id into a listmenu??

 

<select name="listmenu" size="1" id="listmenu">

<option selected="selected">Please select category</option>

<option>1</option>

<option>2</option>

<option>3</option>

<option>4</option>

</select>

 

 

basically i would like it to say something like

 

if (form1.listmenu.value = "Please select category")

{

        document.getElementById(listmenu_error').innerHTML = 'You did not choose a category.';

        valid = false;

}

 

I have tried a couple variations,, but I'm still new to all this.. Anyone have any input?

 

 

Link to comment
Share on other sites

<select name="listmenu" size="1" id="listmenu">
<option selected="selected" value="0">Please select category</option>
<option value="1">1</option>

Assign values to the option tags, as the innerHTML is just a text representation.  Check the values by using the selectedIndex's value.

 

if (form1.options[options.selectedIndex].value == "1") {
//do something
}

The if statement should be accurate, but if not google "selectedIndex" to find the right way.  You might have to change the referencing in relation to your form/select names.

Link to comment
Share on other sites

justAnoob, just dropping by to ask that for future reference, please use a more descriptive thread title (like perhaps 'listmenu validation help' or something along those lines in this case), and not something like 'anyone?'. Being descriptive helps give other members a better idea of the issue at hand at a glance (and as a result, you might get their participation instead of them simply passing you by deliberately).

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.