View Full Version : Javascript help, please?
Boofo
07-12-2004, 04:02 PM
Can anyone help me out with the following, please?
The javascript for what I am wanting to do is as follows:
function alert( header, message ) {
parent.applet.document.ChatClient.alert( header, message );
}
As far as I can tell, this works fine. The problem I am having is with the following code:
<td>
<form name=Warn>
<B>Warn:</B> <select onchange="javascript:alert(this.options[selectedIndex].value);">
<option value="">--------</option>
<option value="Hi _USER_!";"Is everything ok?">Hi there!</option>
</select>
</form>
</td>
How do I make an options that contains both the header AND the message in the drop down here? I know what I have for the option isn't right. ;)
Thank you in advance. ;)
Natch
07-12-2004, 10:56 PM
OK - the way I have done this (implemented for vBWar ;)) is as follows:
You need an multi-dimensional array in a single array that javascript can manage...
Try:$boofosarray[$header.":".$message] = $displayvalue;The trick is to generate your Select menu in PHP with values that don't work ($header.":".$message) and then explode it out in your javascript function which then pops up your alert.
Should work ;) So instead of putting your javascript call right there in the onchange, try putting a function call in there onchange="return gimmesomesugar(this.options[selectedIndex].value);" with the function <script type="text/javascript">
<!--
function gimmesomesugar(sugar)
{
var somesugar = sugar.split(":");
parent.applet.document.ChatClient.alert( somesugar[0], somesugar[1] );
}
//-->
</script>somewhere on your page ;) prolly better off in the <head>
Let me know how u go pal ;)
[FYI: never name your custom javascript functions with the name of a default js function like "alert" ;)]
Boofo
07-12-2004, 11:06 PM
OK - the way I have done this (implemented for vBWar ;)) is as follows:
You need an multi-dimensional array in a single array that javascript can manage...
Try:$boofosarray[$header.":".$message] = $displayvalue;The trick is to generate your Select menu in PHP with values that don't work ($header.":".$message) and then explode it out in your javascript function which then pops up your alert.
Should work ;) So instead of putting your javascript call right there in the onchange, try putting a function call in there onchange="return gimmesomesugar(this.options[selectedIndex].value);" with the function <script type="text/javascript">
<!--
function gimmesomesugar(sugar)
{
var somesugar = sugar.split(":");
parent.applet.document.ChatClient.alert( somesugar[0], somesugar[1] );
}
//-->
</script>somewhere on your page ;) prolly better off in the <head>
Let me know how u go pal ;)
[FYI: never name your custom javascript functions with the name of a default js function like "alert" ;)]
The javascript I posted above it how it has to be. This is for realchat and that's how he says to do it in the program. I have a page called extras that this is located on and where the rest of it has to go. Not much I can do about that, I'm afraid. This code goes in an html page, by the way.
The drop down was my idea as I wanted to be able to click it and have it send a warning to the user. There's no way to do that with this? :(
Natch
07-12-2004, 11:18 PM
In your HTML page, can you add any content? like a Javascript function ?
Natch
07-12-2004, 11:50 PM
The javascript I posted above it how it has to be. This is for realchat and that's how he says to do it in the program. I have a page called extras that this is located on and where the rest of it has to go. Not much I can do about that, I'm afraid. This code goes in an html page, by the way.
The drop down was my idea as I wanted to be able to click it and have it send a warning to the user. There's no way to do that with this? :(
<td>
<form name=Warn>
<B>Warn:</B> <select onchange="javascript:alert(this.options[selectedIndex].value);">
<option value="">--------</option>
<option value="Hi _USER_!";"Is everything ok?">Hi there!</option>
</select>
</form>
</td>
Change this to
<td>
<form name="warn">
<B>Warn:</B> <select onchange="gimmesomesugar(this.options[selectedIndex].value);">
<option value="">--------</option>
<option value="Hi _USER_!:Is everything ok?">Hi there!</option>
</select>
</form>
</td>
Add somewhere in the <head> tags<script type="text/javascript">
<!--
function gimmesomesugar(sugar)
{
var somesugar = sugar.split(":");
alert( somesugar[0], somesugar[1] );
}
//-->
</script>This should call the same alert function you have scripted in your first post, unless the regular javascript alert() function steps in and takes over ;)
Boofo
07-13-2004, 12:42 AM
ok, that works, but it throws a popup up for this line:
--------
when I take it back to the beginning of the list. Can we fix that so it doesn't do anything for the first option like that?
Natch
07-13-2004, 12:59 AM
Yeah - give it a value in your SELECT and test for that value in the javascript before throwing to the alter...
Try this<script type="text/javascript">
<!--
function gimmesomesugar(sugar)
{
var somesugar = sugar.split(":");
if(somesugar.length==1)
{ return false; }
alert( somesugar[0], somesugar[1] );
}
//-->
</script>
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.