javascript problem

Status
Not open for further replies.
G

Guest

Guest
i m using java scroipt in my page. now i have one problem in that.

in that i have two simple buttons eg button1 and button2. on both i need to triger diff fuction respectively fun1 and fun2 . now fun1 fires while pessing button1 . but while pressing button2 , fun2 doesnt.

if i give in button2 to triger fun1 it runs ..

how can it be? any solution ?
 

Deep

Version 2.0
actually from looking at the description it looks like that he has mentioned name of function fun1 in button 2 (he should have mentioned fun2 function there)

but lets see the code :)

Deep
 

KnightRider

Broken In
well its understandble the way you are describing but i think u must paste the code...that wil be a easy way to look up..
 
OP
G

Guest

Guest
look the code .. in this there is two buttons B1,B2 . on B1 i fire triger function and on B2 i fire clear function . this clear fuction is not working aat all

Code:
<html>


    
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Fun</title>
<meta name="Microsoft Theme" content="topo 011">
</head>
<script type="text/javascript" language="javascript"> 
<!-- 

// A simple JavaScript to remove duplicate characters from a String. 
// 
function filter (str, pre) 
{ 
   var ctr ; 
   var chr ; 
    
   // alert (str) ; 
    
   var tmp = str.split (" ") ; 
   str = tmp.join ("") ; 
    
   // alert (str) ; 
    
   var len = str.length ; 
    
   // alert (len) ; 
    
   for (ctr = 0 ; ctr < len ; ctr++) 
   { 
       
      chr = str.charAt (ctr) ; 
      if (str.lastIndexOf (chr) != ctr) 
      { 
       
         // alert (chr) ; 
          
         tmp = str.split (chr) ; 
         str = tmp.join ("") ; 
          
         // str = str.replace (chr, "") ; 
         // alert (str) ; 
          
         if (typeof (pre) == "undefined" || pre == 0) 
         { 
            ctr-- ; 
         } else 
         { 
            // alert (str + ", " + ctr + ", " + chr + ", " + str.length) ; 
            str = str.substring (0, ctr) + chr + str.substring (ctr, str.length) ; 
            // alert (str) ; 
         } 
          
         len= str.length ; 
      } 
   } 
    
  //alert(str);
   l = str.length;
  // alert(l);
   l= l%5;
  // alert(l);
  	//alert(ss)


}
function triger()
{
	if(document.forms[0].T1.value=="" || document.forms[0].T2.value == "")
	{
	alert("Enter both fields");
	return;
	}
	var str;
	str = document.forms[0].T1.value+document.forms[0].T2.value;
	filter(str);
	
}

function clear()
{
	alert("aAa");
	document.forms[0].t1.value="";
	document.forms[0].t2.value="";
	document.forms[1].t1.value="";
}
	
//--> 
</script>

<body>



</p>
<div align="center">
  <center>
  <table border="0" cellpadding="0" cellspacing="0" width="100%" style="border-collapse: collapse">
  <tr>
    <td width="150" align="center"></td>
    <td align="right">
    <!--webbot bot="Navigation" s-type="banner" s-rendering="graphics" S-Orientation B-Include-Home B-Include-Up U-Page S-

Target --></td>
  </tr>
  <tr>
    <td width="100%" colspan="2" valign="top">
    <!--webbot bot="Navigation" S-Type="sequence" S-Orientation="horizontal" S-Rendering="graphics" B-Include-Home="TRUE" B-

Include-Up="FALSE" U-Page="sid:1009" --></td>
  </tr>
  <tr>
    <td width="150" align="center"></td>
    <td>

This is a simple Fun game which is variant of well known 
    FLAMES . in that you enter your name and name of anyone and click to find 
    can you marry or you are enemy ..</p>
    

</td>
  </tr>
  <tr>
    <td width="150" align="center"></td>
    <td></td>
  </tr>
  <tr>
    <td width="150" align="center"></td>
    <td>
    <form action="--WEBBOT-SELF--" method="POST" onSubmit="location.href='_derived/nortbots.htm';return false;" webbot-

onSubmit    >
     
      <!--webbot bot="SaveResults" u-file="_private/form_results.csv" s-format="TEXT/CSV" s-label-fields="TRUE" startspan --

><input TYPE="hidden" NAME="VTI-GROUP" VALUE="0">Your Name 

:
      <input type="text" name="T1" size="20"></p>
      

Your Partner's Name : <input type="text" name="T2" size="20"></p>
      


      
[color=darkred]<input type="button" value="Enter" name="B1"  ONCLICK= "triger()" 

>&[/color]nbsp;
   
   [color=red]<input type="button" value="clear" name="B2" ONCLICK= "clear()"></[/color]p>
      
    


    </form>
    <form method="POST" action="--WEBBOT-SELF--" onSubmit="location.href='_derived/nortbots.htm';return false;" webbot-

onSubmit>
      


      See Your Result here : <input type="text" name="T1" size="20"></p>
    </form>
    <p align="center"></p>
    

[size="1"]
    <!--webbot bot="Navigation" s-orientation="horizontal" s-rendering="html" s-bar="Bars" s-btn-nml="&lt;A 

HREF=&quot;#URL#&quot; TARGET=&quot;#TARGET#&quot; STYLE=&quot;text-decoration: none;&quot;&gt;#LABEL#&lt;/A&gt;" s-btn-

sel="#LABEL#" s-btn-sep="&amp;nbsp;|&amp;nbsp;" s-type="siblings" b-include-home="TRUE" b-include-up="FALSE" -->[/size]</p>
    

</td>
  </tr>
</table></center>
</div>



</body>

</html>
 

Deep

Version 2.0
hmm function name clear seems to be reserved name..rename the function to something else..it will work :)

btw why are you using function to clear the fields? just use type="reset" it will do the job :)

Deep
 

the_moon

Journeyman
Exactly!
For clearing the fields, u can simply use type="reset" and the job will be done my friend!!
No need to get into so much hassels atall!!
 

Deep

Version 2.0
I have already mentioned the reason...

clear is reserved name so cant be used for function...

if you rename it to clear1 then it will work :)

Deep
 
OP
G

Guest

Guest
ok thx i will try .. and you knw in this i have three text box and they are in diff forms so reset button of that form will not reset textbox of other form na so i want to use. .. and you are also rite i can put all this is in one form and use reset . . but after i was some lazy to change it so went for function. .
 

Deep

Version 2.0
lol get everything in one form and then do it..thats my suggestion :)

Edit: oh great to hear that it worked for u :)

good luck
Deep
 

tuxfan

Technomancer
Deep man, you are pretty fast :) By the time I came back, you've already solved the problem!!

But somehow I am more comfortable with PHP then Javascript. Of course, they both compliment each other, one being used mainly for server side scripting and the other mainly for client side scripting.

But I don't know why I am more comfortable with PHP. May be because PHP code can't be seen just by viewing page source in browser ;)
 

Deep

Version 2.0
tuxfan said:
Deep man, you are pretty fast :) By the time I came back, you've already solved the problem!!

But somehow I am more comfortable with PHP then Javascript. Of course, they both compliment each other, one being used mainly for server side scripting and the other mainly for client side scripting.

But I don't know why I am more comfortable with PHP. May be because PHP code can't be seen just by viewing page source in browser ;)

actually I too prefer PHP and I am not at all good at javascript but you know sometimes javascript is very useful specially for some quick validations...like blank fields etc...

takes less time but ofcourse i would do server side validations as well along with javascript ;)

Deep
 
OP
G

Guest

Guest
hey this all working fine till now . now i get other error .. in this as i gave code i have writen like document.forms[0].t1.value="" so when i execute on browser from net i get error like error at some line error : document.forms.0.T1.value is null or not an object !!!

when i saw source from view source it is like original means forms[0] , while in error brackets are not there !!!

now what to do?
 

Deep

Version 2.0
yup it will show error coz you have given wrong variable names in clear function...

Code:
   document.forms[0].t1.value=""; 
   document.forms[0].t2.value=""; 
   document.forms[1].t1.value="";

your form field names are T1 AND T2.

variable names are case sensitive

Deep
 
Status
Not open for further replies.
Top Bottom