Page 1 of 1

Javascript onDblClick help

Posted: Sun Feb 27, 2005 4:18 pm
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.

Posted: Sun Feb 27, 2005 4:41 pm
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...:?

Posted: Sun Feb 27, 2005 5:21 pm
by cbrian
Doesn't work for me :(

Posted: Sun Feb 27, 2005 5:42 pm
by feyd
did you copy the code I posted and try it? or just stare at your code some more?

Posted: Sun Feb 27, 2005 6:58 pm
by Joe
What browser are you using and are you sure you have the correct js configurations etc?.

Posted: Mon Feb 28, 2005 2:44 pm
by cbrian
Feyd: I copied and pasted your code.

Joe: I'm using the latest Internet Explorer and my host does have Javascript.

Posted: Mon Feb 28, 2005 4:50 pm
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

Posted: Tue Mar 01, 2005 3:13 pm
by cbrian
Erg. Sorry, I'm very stupid. Still doesn't work for me.