Javascript help

Feras

Baseband Member
Messages
60
Hello

I want a code in javascript with the form below:

- a select form allow the visitor to chose a topic

- a box under the select form show explaining about the selected topic


I want another script that forces the visitor to insert 15 numbers in the text field


Thank you very much :)
 
Search in google for Dynamic Drive(first place), you will find a website with a great collections of javascript. The second script you request it's there.
 
Here is something I typed up real fast.
In the <head> section of your page
Code:
<script type="text/javascript">
<!--
     var descriptions = new Array(5);
     descriptions[0] = "Description 1";
     descriptions[1] = "Description 2";
     descriptions[2] = "Description 3";
     descriptions[3] = "Description 4";
     descriptions[4] = "Description 5";
     function listChanged(obj) {
          var curIndex = obj.selectedIndex;
          var curValue = obj.options[curIndex].value;
          if(Number(curValue).toString() != 'NaN' || Number(curValue) < 0) { // make sure it's a valid number
              document.getElementById('output').innerHTML = descriptions[curValue];
          } else {
              document.getElementById('output').innerHTML = "Please select an item to view it's description.";
          } // end if/else
      } // end function
//-->
</script>
Later on in the body section of your page and inside of your form

Code:
<select id="itemSelection" name="itemSelection" onchange="listChanged(this);">
 <option value="-1" selected>--Select--</option>
 <option value="0">First Item</option>
 <option value="1">Second Item</option>
 <option value="2">Third Item</option>
 <option value="3">Fourth Item</option>
 <option value="4">Fifth Item</option>
</select>
</form>

<div id="output">
  Please select an item to view it's description.
</div>
Hope this helps.

You can change the text for each of the descriptions and this will be updated when they change options.

If you can provide a little more information about what you're trying to do, I can help with the second script also.
 
Hi

Mr. perseadrian
The web site Dynamic Drive is a really library for web scripts

Thank you :)

Mr. Daeva
Your script is 100% ok

Thanks alot :)
 
Back
Top Bottom