Javascript onDblClick help

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
cbrian
Forum Commoner
Posts: 97
Joined: Sun Feb 27, 2005 12:29 pm

Javascript onDblClick help

Post by cbrian »

What I'm trying to do here is, when you double click on a form select, it inserts '/msg $id' (this is within PHP) into a text form. Here's some snippets from the code. So far, it doesn't work.

Code: Select all

<script language="javascript">
function insert(pusername) &#123;
document.form.message.value = "/msg "
&#125;
</script>

Code: Select all

<form name="form" action="game.php?where=chat" method=POST>
<input name="message" type=text size=40 maxlength=100>
<input type=submit name="submit" value="Chat">

Code: Select all

print("<select size=17 name="people" style="width:150">");
print("<option value="$puserid" ondblclick="insert('$pusername')">$pusername</option>");
print("</select>");
The $puserid and $pusername have been defined already.

Thanks for any help you can give me.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

<html>
	<head>
		<script language="Javascript">
			function insert(pusername) &#123;
				document.forms&#1111;'form'].elements&#1111;'message'].value = "/msg " + pusername;
			&#125;
		</script>
	</head>
	<body>
		<form name="form" action="game.php?where=chat" method="POST">
		<input name="message" type="text" size="40" maxlength="100">
		<input type=submit name="submit" value="Chat">
		<select size="17" name="people">
			<option value="10" ondblclick="insert('foo')">foo</option>
			<option value="11" ondblclick="insert('bar')">bar</option>
			<option value="12" ondblclick="insert('bla')">bla</option>
		</select>
		</form>
	</body>
</html>
sure seems to work...:?
cbrian
Forum Commoner
Posts: 97
Joined: Sun Feb 27, 2005 12:29 pm

Post by cbrian »

Doesn't work for me :(
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

did you copy the code I posted and try it? or just stare at your code some more?
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

What browser are you using and are you sure you have the correct js configurations etc?.
cbrian
Forum Commoner
Posts: 97
Joined: Sun Feb 27, 2005 12:29 pm

Post by cbrian »

Feyd: I copied and pasted your code.

Joe: I'm using the latest Internet Explorer and my host does have Javascript.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Joe: I'm using the latest Internet Explorer and my host does have Javascript.
Huh? Your host does...?? JavaScript runs in your own browser dude, not on the host :P Feyd's code works for me in IE6 and Moz Firefox
cbrian
Forum Commoner
Posts: 97
Joined: Sun Feb 27, 2005 12:29 pm

Post by cbrian »

Erg. Sorry, I'm very stupid. Still doesn't work for me.
Post Reply