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 3 of 3
  1. #1
    Regular Coder
    Join Date
    Apr 2003
    Location
    Seoul, Korea
    Posts
    329
    Thanks
    0
    Thanked 0 Times in 0 Posts

    javascript collision

    Code:
    <script language="JavaScript">
    function validate(SF)
    {
    var word = SF.SW.value
    if (word.length == 0 )
    {
    alert('please,enter something')
    return false 
    }
    }
    </script> 
    					
    <form action="seach_result.php" name="SF" onSubmit="return validate(SF)">	
    	<input type="Text" name="SW" value="" size="12" maxlength="30"> 
    	<input type="submit" value="search">		
    </form>
    The above javascript is for alert. and the below javascript is for <b></b>.
    Code:
    <script type="text/javascript">
       function appendValue(str)
      {
      document.forms[0]['t'].value += str;
      }	
    </script>
    
    <form action="form_action.php">
    	
    <input type="button" value=" b " onclick="appendValue('<b>');">
    <input type="button" value=" /b " onclick="appendValue('</b>');">
    <textarea name="message" id="t" cols="76" rows="20"></textarea>
    <input type="submit" value="Submit">
    </form>
    The two javascripts work fine each but they don't work fine together in the following code.
    Code:
    <script language="JavaScript">
    function validate(SF)
    {
    var word = SF.SW.value
    if (word.length == 0 )
    {
    alert('please,enter something')
    return false 
    }
    }
    </script> 								
    <form action="seach_result.php" name="SF" onSubmit="return validate(SF)">	
    	<input type="Text" name="SW" value="" size="12" maxlength="30"> 
    	<input type="submit" value="search">		
    </form>
    
    <script type="text/javascript">
       function appendValue(str)
      {
      document.forms[0]['t'].value += str;
      }	
    </script>
    
    <form action="form_action.php">
    	
    <input type="button" value=" b " onclick="appendValue('<b>');">
    <input type="button" value=" /b " onclick="appendValue('</b>');">
    <textarea name="message" id="t" cols="76" rows="20"></textarea>
    <input type="submit" value="Submit">
    </form>
    Do you see what is the reason for script error in the above code and any solution?

  • #2
    Regular Coder
    Join Date
    Jul 2003
    Location
    Massachusetts
    Posts
    472
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Change this line:
    Code:
    document.forms[0]['t'].value += str;
    To this:
    Code:
    document.forms[1]['t'].value += str;

  • #3
    Regular Coder
    Join Date
    Apr 2003
    Location
    Seoul, Korea
    Posts
    329
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you. it works.


  •  

    Posting Permissions

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