...

View Full Version : javascript collision



joonstar
12-22-2003, 05:31 AM
<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>.


<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.


<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?

fredmv
12-22-2003, 05:44 AM
Change this line:
document.forms[0]['t'].value += str;To this:
document.forms[1]['t'].value += str;

joonstar
12-22-2003, 06:26 AM
Thank you. it works.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum