faqts : Computers : Programming : Languages : JavaScript

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

1 of 3 people (33%) answered Yes
Recently 1 of 3 people (33%) answered Yes

Entry

Cursor doesn't set at first col and row in text area, cannot validate it using value.length

Apr 6th, 2008 20:09
ha mo, Colin Fraser, moody headmann,


The position of the cursor is irrelevant to the validation of a string.
I suspect the error lies with the use of the "value" property. Try
placing the string into a variable eg: 
    <form name="myForm">
    <textarea name="area51"> </textarea>
    var astring = myformname.area51.value 
    <input type="button" value="Submit" onClick ="validate(astring)" > 
then using something like 
<script><!--
function validate(astring) {
    var ok = false 
    var good="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
    for (var i=0; i<astring.length; i++) {
        if (good.indexOf(astring.charAt(i)) < 0) {
            alert('Sorry, you have invalid characters, please try      
            again'); }
        else {
            ok = true   
        }
    }
    if (ok)  {
          myformname.submit()
    } 
} 
//--></script>
The submission actually takes place in the validation function, which
may not always be the best way of handling this, and I currently have no
way of testing this submission, but it should work... 
Good luck
http://www.businessian.com
http://www.computerstan.com
http://www.financestan.com
http://www.healthstan.com
http://www.internetstan.com
http://www.moneyenews.com
http://www.technologystan.com
http://www.zobab.com
http://www.healthinhealth.com