[Javascript] check value on the fly input tag

David Lovering dlovering at gazos.com
Thu Sep 18 10:23:44 CDT 2003


I think there's something that should be said here -- while it is perfectly
feasible to insert objects on the fly into an already created table as the
result of a keypress, click, or whatever, it is pretty much limited to
"createElement" calls and the like.

Secondly, one can't simply issue a JavaScript call via lagi, alter an
object's innerHTML attribute and create a whole new object without making
sure that the intended parent object exists first.

Thirdly, "checking a value" has absolutely NOTHING to do with creating a new
input object -- it is much easier than that, i.e;

function readVal(i) {
   if (!i) { return -1; }
   if (i == "") { return -1; }
  var myObj = eval('document.forms[0].cek' + i );
  if (!myObj) { return -1; }
  var myValue = myObj.checked;
  return myValue;
}

function setVal(i) {
  if (!i) { return -1; }
  if (i == "") { return -1; }
  eval('document.forms[0].cek' + i + '.checked = \'' + true + '\'');
}

Obviously, these code snippets need extensive hardening before insertion
into a working application, i.e; they should check to make sure i is an
integer less than the number of actual "cek" objects, etc. etc.

Perhaps I don't really understand what you are trying to do -- looking over
your code has caused me more confusion that enlightenment.

-- Dave Lovering


----- Original Message ----- 
From: "andy susanto" <andy78 at centrin.net.id>
To: <javascript at LaTech.edu>
Sent: Wednesday, September 17, 2003 4:54 PM
Subject: [Javascript] check value on the fly input tag


> hai,
>
>  i am try to check a value on the fly input tag, can anyone help to solve
my
> problem ?
>
> this is my code :
>
> <HTML>
> <HEAD>
> <STYLE>
>       #contentpage {color:#000000; font-size:11pt; width:388};
> </STYLE>
> <SCRIPT>
> i=0;
> w="";
> function createobj(isi){
>   w += isi;
>   document.all['test'].innerHTML = "<table><tr><td>Kode
> </td><td>Description</td><td>Jumlah</td></tr>"+w+
>    "<tr><td><Input type='button' ONCLICK='lagi()'></td></tr></TABLE>";
> }
>
> function lagi(){
>   isi = "<tr><td><INPUT Type='checkbox' Name='cek'+i Value=1
CHECKED><INPUT
> TYpe='text' Name='kd'+i VALUE=''></td>"+
>    "<td><INPUT TYpe='text' Name='des'+i VALUE=''></td>"+
>    "<td><INPUT TYpe='text'Name='jml'+i
> ONBLUR=alertvalue('jml',eval('document.forms[0].jml'+i+'value'))
> VALUE=''></td></tr>";
>   createobj(isi);
>   i++;
>
> }
>
>
> function alertvalue(obj,idx){
>   kode = 'kd'+idx;
>   jumlah = 'jml'+idx;
> alert(obj);
>   alert(idx);
>   if (obj=='jml'){
>     if (jumlah.value == 'undefined'){
>       alert('Hai Your Value is 2');
>       lagi();
>     }
>     else{
>        alert('Hai Your Value is not 2');
>
>     }
>   }
> }
>
> </SCRIPT>
> </HEAD>
> <Body onload= 'createobj("");'>
>
> <Form Name='tt'>
> <TABLE><TR>
> <TD ID='test'></TD></TR>
> </TABLE>
> </FORM>
>
> </Body>
> </HTML>
>
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
>
>





More information about the Javascript mailing list