Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7530565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:56:44+00:00 2026-05-30T04:56:44+00:00

I have this html code test.html : <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN

  • 0

I have this html code test.html:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="jquery.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>

<script type="text/javascript">
  $(document).ready(function() {
    var course_data;     
    $.get('exerc.xml', function(data) { 
    course_data = data;               
    var that = $('#courses'); 
    $('course', course_data).each(function() {
    $('<option>').text($(this).attr('title')).appendTo(that);
    });
  }, 'xml'); 

 $('#courses').change(function() { 
    var val = $(this).val(); 
    var that = $('#times').empty(); 
    $('course', course_data).filter(function() { 
      return val == $(this).attr('title'); 
    })
    .find("lesson").each(function() { 
      $("#lesson").val($(this).text());   
    });
 });
 });
 </script>

<script type="text/javascript">
function keyPressed(event, input) {
   if (event.keyCode == 8) {
               // Allow backspace
   return true;
  }
              // Detect character code: event.which on Firefox, event.keyCode on IE
   var char = event.which ? event.which : event.keyCode;
             // Convert to string
   char = String.fromCharCode(char);
   var exerc = new Array();
   exerc = "1234 1234 1234";
    // Compare to character in match string and return result
   return (exerc.charAt(input.value.length) == char);
   }
</script>   
</head>

<body>
 <form method="post" action="">
 <input type="text" size="90" id="lesson" />
 </form>
 <form  id="form2" name="form2" method="post" action="">
 <input size="90" type="text" class="textarea" onkeypress="return keyPressed(event, this);" />
 </form>

 <form name="form1">
 <p>exercices
   <select style="width:100px" id='courses'>
   <option selected="selected">choose...</option>
   </select>
 </form> 
 </body>
 </html>

And this is my xml file exerc.xml:

 <?xml version="1.0" encoding="utf-8"?>
 <courses>
    <course title="exercise 1">
        <lesson>1234 1234 1234</lesson>
    </course>
    <course title="exercise 2">
        <lesson>5678 5678 5678</lesson>
    </course>
    <course title="exercise 3">
        <lesson>9012 9012 9012</lesson>
    </course>
 </courses>

Well, there are two inputs fields above in the first code. In the first input enter the data from the xml file (parser method). This is depend on the choice from dropdown menu. In the second input i use a function (keyPressed) which allow me to enter the same data that depict in the first input, but in order one by one. This is work very well with the first exercise. The problem is that i want to work with more exercises. I add an array with more exercises like this:

 var exerc = new Array();
   exerc[0]= "1234 1234 1234";
   exerc[1] = "5678 5678 5678";
   exerc[2] = "9012 9012 9012"; 

I change the first function keyPressed, but it is doesn’t work. Beybe it is totally wrong:

 function keyPressed(event, input) {
    if (event.keyCode == 8) {
    return true;
    }
    var char = event.which ? event.which : event.keyCode;
    char = String.fromCharCode(char);
     var exerc = new Array();
       exerc[0]= "1234 1234 1234";
       exerc[1] = "5678 5678 5678";
       exerc[2] = "9012 9012 9012";
      for (i=0;i<exerc.length;i++){
      document.getElementById("courses").selectedIndex;
      }
     return (exers.charAt(input.value.length) == char);
   }

I use this exercise like a game. I can add or removes exercises from xml file and I learn the provision of keys. Maybe it is stupid for many people here, but i found it interesting. So, i stack here. Any suggestion how to fix it? Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T04:56:46+00:00Added an answer on May 30, 2026 at 4:56 am

    this is the solution, if someone have the same problem!

    var exerc = ["1234 1234 1234","5678 5678 5678","9012 9012 9012"]; 
    for (i=0;i<exerc.length;i++){
    
    var option=document.getElementById("courses").selectedIndex;
    }
    
    return (exerc[option - 1].charAt(input.value.length) == char);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following page with iframes: <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN
I have this small HTML document: <!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.0 Transitional//EN> <html>
I have this simple code in facelets numbers.xhtml: <?xml version='1.0' encoding='UTF-8' ?> <!DOCTYPE html
I have code like this: string uriString = @C:\Temp\test.html; Uri uri = new Uri(uriString);
I have this HTML code for radios: <input type='radio' name='a_27' value='Yes' id='a_27_0' /> <input
I have this html code that i want to edit with jQuery. Here is
I have this html code <html> <head> <title>JQuery Problem 2</title> <script type=text/javascript src=jquery-1.4.min.js></script> <script
I have this HTML code: <div class='com_box'> <div class='com_box_c'> <div class='com_box_info'> <a id='quote'>quote</a> </div>
i have this code $(function() { $('#ans_vote a span').click(function(){alert('working');return false;});}); and this html <div
I have HTML code like this : <div> <a>Link A1</a> <a>Link A2</a> <a>Link A3</a>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.