Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

can't get function to fire 2

Status
Not open for further replies.

simon551

IS-IT--Management
May 4, 2005
249
Hi,

I validated my html at w3 validator but I can't get this script to fire:

newTicket.js
Code:
function getname(trav){
	var trav=document.getElementById('traveler').value;
	if (trav != "Non-Employee"){
			document.getElementById("traveler_name").type="text";
			setTimeout('document.getElementById("traveler_name").focus()',100);
	}
	}
//this function calls the other on the changing of name
function writeName(){
	document.getElementById('traveler').onchange=getname;
}

I call it here:
Code:
<script src="../Scripts/newTicket.js" type="text/javascript"></script>
<script type="text/javascript">window.onload=writeName();</script>

and this is my form field:
Code:
<select name="traveler" id="traveler">
        <option value="null">--please select--</option>
        <option value="Non-Employee">Non-Employee</option>
        <?php
do {  
?>
        <option value="<?php echo $row_rsEmployees['EmpID']?>"><?php echo $row_rsEmployees['Employee']?></option>
        <?php
} while ($row_rsEmployees = mysql_fetch_assoc($rsEmployees));
  $rows = mysql_num_rows($rsEmployees);
  if($rows > 0) {
      mysql_data_seek($rsEmployees, 0);
	  $row_rsEmployees = mysql_fetch_assoc($rsEmployees);
  }
?>
      </select>
 
When you say "can't get it to fire", do you mean it isn't called at all, or it doesn't do what you expect?

Some thigs to confirm:

1) You have a single element with an ID of "traveler_name" on your page (your code refers to this, but it's not in the HTML you posted)

2) Your fuction is being called at all (put an alert right at the top of it).

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Hi

There is a difference between
Code:
[gray]// assign the return value of the writeName() function to the onload[/gray]
window.onload=writeName();

[gray]// assign the writeName() function to the onload[/gray]
window.onload=writeName;

Feherke.
 
Thank you both! Both tips were very helpful. I got it to run.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top