Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Apr 2014
    Location
    New Zealand
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    (Just started learning!) How would you check only alphabets, and plindromes?

    Hello, I am learning about HTML, Javascript and probably PHP for the future webdesigning paper I would be doing in Uni.

    I lack computer skills (my major is not computer science,, it is Business).
    So I asked the lecturer to help me study/prepare for the future paper. It's only been a week I have been learning webdesigning, so please udnerstand if I can't udnerstand the first time! haha.

    I got some sample exercise Questions, and the lecturer told me that I could use Google to do this, (becuase in real-life programmers use Google too?)
    He said it should only take 1 hour to do everything, but I am stuck.

    So far,
    I did the layout, textbox1, textarea.

    However now that I have to use Javascript, the three questions that I attempted but did not work was:

    Q7: When somethign is typed into the Textbox1, only a-z and A-Z should be allowed and when anything else would display an error pop up that would say "Must only contain alphabets!" (I was told to do onblur for the textbox)

    I wrote the code, but it does not do anything. The code that I wrote for Q7 was:
    Code:
    ...
    <script>
     
    //this "errorinfield" code I do not fully understand, but lecturer's example had it so I copied it first:
      function errorinfield(whichcontrol, errormsg){
        alert(errormsg);
        whichcontrol.focus();
        whichcontrol.select();
        return false;
      }
    
      function valid(whichcontrol) {
            var re = /^[a-zA-Z]*$;
            if (!re.test(whichcontrol.value)) {
                alert('Must only contain alphabets!');
                whichcontrol.value = whichcontrol.value.replace(/^[a-zA-Z]*$/g,"");
            }
        }
    </script>
    
      </head>
      <body>
      <form name="exercise1" method="post" action="exercise1.php">
      <table>
        <tr>
    	  <td align="right"><Font Color="Yellow">One word:</td>
    	  <td>
    	  <input type="text" name="textbox1" onblur="valid(exerc.textbox1)" />
    ...
    However, when I type any numbers and click away from the textbox, nothing happens. What am I missing? Am I linking the Javascript to HTML wrong?

    Next question was:
    Q8: Using Javascript, test if the word typed into Textbox1 is a plaindrome. Palindrome is "Anna" and "Bob", but not "Car". Write a span next to the textbox1 to show it is "Yes" or "No"

    I used google to find this code:

    Code:
    function isPalindrom(str) {
        return str == str.split('').reverse().join('');
    }
    However.. my knowledge stops here. Even if I write this in the <script>, I do not know how to link it to the textbox1, because it is already linked the one from Q7 ( ...onblur="validateletter(test1.textbox1)" )...
    Also, I am not sure if this is all the code I need for Q8.



    The last question I could not attempt was:
    Q9: Now for the Textarea, any sentence can be written in there. Count the number of plindromes in the sentence and display it next to the textarea. It should show as span, "Palindromes = x"

    I asked the lecturer, he said use the "split" function. But I have found that split function but it was for Q8, when I found it on Google.



    I am sorry that I am asking so much at once, I want to understand and finish it by Monday for further progress on my learning.
    Hopefully it does not take long like the lecturer said!

  • #2
    New to the CF scene
    Join Date
    Apr 2014
    Location
    New Zealand
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    sorry this is the wrong place to post this! I cannot delete this thread, could the administrator please delete this? sorry!


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •