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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getElementById()

Status
Not open for further replies.

rachelason

Programmer
Jun 28, 2004
114
GB
Hi! i am trying to get a value of a textbox from a javascript file and then display it. It's a simple program i am testing because i have a bigger problem.
my code is

<html>
<head>
<title>index</title>
<script language="javascript" src="c.js" type="text/javascript">

</script>
</head>

<body>
<form name="myform" >
<input type="text" name="mytext" size="20" >

<input type="button" value="Show" onClick="javascript:sayHello('mytext');">

</form>


</body>
</html>

and the javascript file is

function sayHello(text1){
var temp1=document.getElementById(text1).value;
document.write(temp1);
}

I can't make the javascript file to pickup the value from the textbox....
Can someone correct my mistake? Thanks
 
No I want the value, but when I write document.getElementById('my_sess_id').value, the page just displays a blank. This only happens in Netscape. I've also tried document.getElementById('my_sess_id').name, but that doesn't do it either.
 
Oh, and just to add, with the code just getting the element only, it returns null. But I don't understand why it's null when there definitely IS an element on the webpage and when IE sees it.
 
If my_sess_id is a form field with type=hidden, there is no reason that

[tt]document.form_name.my_sess_id.value[/tt]

shouldn't work in Netscape, unless you've somehow disabled JavaScript in Netscape.

*cLFlaVA
----------------------------
A pirate walks into a bar with a huge ship's steering wheel down his pants.
The bartender asks, "Are you aware that you have a steering wheel down your pants?"
The pirate replies, "Arrrrr! It's driving me nuts!
 
Yep, I tried that too. It just gives me a blank page. (But the source is intact.) Javascript is not disabled. It's interesting that it returns 'null' and not 'undefined' when it looks for the element though.

I'll figure it out eventually...thanks for all your time today.
 
Got it!!! I moved the hidden field and the form it was in further up in my code ABOVE the place where I had these lines:

<script language="JavaScript1.2" src="MenuRollovers_toppro.js"></script>
<script language="JavaScript1.2" src="Browser_Check.js"></script>


Once I did this, Netscape recognised that there was an element. Oh WHAT A RELIEF!!! Can't believe I wasted so much time on this. I hope this helps other people.
 
Posting your code would have solved this problem almost immediately!

*cLFlaVA
----------------------------
A pirate walks into a bar with a huge ship's steering wheel down his pants.
The bartender asks, "Are you aware that you have a steering wheel down your pants?"
The pirate replies, "Arrrrr! It's driving me nuts!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top