DotDragnet
May 24, 2012, 02:22:59 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: follow us on twitter @dotdragnet
 
   Home   Help Search Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: js help  (Read 2028 times)
SLEE
Hero Member
*****
Posts: 824



View Profile WWW Awards
« on: June 08, 2007, 05:09:29 PM »

i want to have a select box with two options and a text box. when i
choose the second option in the select box for example 'yes' i want to write some text into the text box for example 'NA'.

how can do this? ive
tried using document.forms[0].element-name.value = 'blah' on onchange but it doesnt seem to work.

help smile
Logged

SLEE - still the most confusing ddner...

Follow me on Twitter
JasonD
Global Moderator
Hero Member
*****
Posts: 551



View Profile Awards
« Reply #1 on: June 08, 2007, 06:01:19 PM »

<select onchange="if(this.value == 'blah')
{this.form.elementname.value='NA';}">

Possibly.
Logged
SLEE
Hero Member
*****
Posts: 824



View Profile WWW Awards
« Reply #2 on: June 09, 2007, 08:21:57 PM »

ok ive advanced on and got things working in ie but i cant seem to
get it to work in firefox??
it should enter 'NA' into the text box if test is chosen else blank te text box.

Code:
<!DOCTYPE html PUBLIC "
-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
/><title>Untitled Document</title>
</head>



<body >

<script>
window.onload = add_event;

/>function change_selection()
{
var target = document.getElementById('texter');
var text = get_selection('lister', false);

if (text == 'test'){
target.value = 'NA';
} else {
target.value = '';
}

}

function
get_selection(target_id, value){
var target = document.getElementById(target_id);
var return_value;
var myindex  = target.selectedIndex


if (value == true){
return_value = target.options[myindex].value;
}else{
return_value = target.options[myindex].text;

}

return return_value;
}

function add_event(){
var target = document.getElementById('lister');
if
(target.addEventListener) {
target.addEventListener ("onchange",change_selection,false);
} else if (target.attachEvent) {

target.attachEvent ("onchange",change_selection);
} else {
target.onchange = change_selection;
}

}

/></script>

<form action="" method="get" name="former">
<select name="lister" id="lister" 
size="1" >
<option value="working" >working</option>
<option value="test" >test</option>
/></select>
<input name="texter" type="text" id="texter"/>
</form>

</body>
</html>


i dont have access to the form so i have to use a listener to update the form.
but why doesnt it work in ff?
Logged

SLEE - still the most confusing ddner...

Follow me on Twitter
JasonD
Global Moderator
Hero Member
*****
Posts: 551



View Profile Awards
« Reply #3 on: June 09, 2007, 10:52:05 PM »

addEventListener takes events without the 'on' prefix.
Logged
SLEE
Hero Member
*****
Posts: 824



View Profile WWW Awards
« Reply #4 on: June 10, 2007, 09:51:47 AM »

excellent thanks jason smile
Logged

SLEE - still the most confusing ddner...

Follow me on Twitter
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF | SMF © 2006-2008, Simple Machines Valid XHTML 1.0! Valid CSS!