using value of textfield as parameter
I know this is a basic question. I asked the same question a while ago, even then thinking it was a simple question. The answer I got seemed to be what I already know and was obvious.. however, when I tried it, it did not work, so I just worked around it for a while... But now the same question is coming up, and this method is still not working...
<p>Name : <input type="text" id="theName" name="theName" value=""></p>
<p><input type="button" name="btnGo" value="Go" onClick="goNow(document.getElementByID('theName').value)"></p>
that is what I currently have, and for some reason it is not working... am I doing something wrong, or why is it not working?
FALL3N
Junior Poster in Training
84 posts since May 2010
Reputation Points: 10
Solved Threads: 2
I know this is a basic question. I asked the same question a while ago, even then thinking it was a simple question. The answer I got seemed to be what I already know and was obvious.. however, when I tried it, it did not work, so I just worked around it for a while... But now the same question is coming up, and this method is still not working...
<p>Name : <input type="text" id="theName" name="theName" value=""></p>
<p><input type="button" name="btnGo" value="Go" onClick="goNow(document.getElementByID('theName').value)"></p>
that is what I currently have, and for some reason it is not working... am I doing something wrong, or why is it not working?
What's not working?!!
Troy III
Practically a Master Poster
609 posts since Jun 2008
Reputation Points: 120
Solved Threads: 80
I know this is a basic question. I asked the same question a while ago, even then thinking it was a simple question. The answer I got seemed to be what I already know and was obvious.. however, when I tried it, it did not work, so I just worked around it for a while... But now the same question is coming up, and this method is still not working...
<p>Name : <input type="text" id="theName" name="theName" value=""></p>
<p><input type="button" name="btnGo" value="Go" onClick="goNow(document.getElementByID('theName').value)"></p>
that is what I currently have, and for some reason it is not working... am I doing something wrong, or why is it not working?
This is your code
<p>Name : <input type="text" id="theName" name="theName" value=""></p>
<p><input type="button" name="btnGo" value="Go" onClick="goNow(document.getElementByID('theName').value)"></p>
What's it supposed to do, because the code provided is absolutely unclear at this point. It doesn't unveil your aim nor what you are aiming to achieve with it
Let's first correct your spelling error on the method first:
<p>Name : <input type="text" id="theName" name="theName" value=""></p>
<p><input type="button" name="btnGo" value="Go" onClick="goNow(document.getElementById('theName').value)"></p>
Now, even if your "goNow" would happen to be the name of some well written function, it should return nothing since the value of your "theName" input is empty by default.
At this point, the "goNow()" [name of some presumed existing function] doesn't tell us much -not even after giving it some seriously deep dark thoughts.
We are after all ordinary coders; some are good, some are better, but in either case -we're no psychics.
Troy III
Practically a Master Poster
609 posts since Jun 2008
Reputation Points: 120
Solved Threads: 80
I really appreciate all your answers, but I think I now know why it is not working.. not sure tho..
this code is for a 'widget' that appears on the homepage of a free hosting site... you enter HTML/javascript and build your custom widget the way you want it.. But the classic DOM structure may not apply... I guess the 'correct' code would be something like:
<p>Name : <input type="text" id="theName" name="theName" value=""></p>
<p><input type="button" name="btnGo" value="Go" onClick="goNow(widget.getElementById('theName').value)"></p>
that's only a guess, but its probably something like that...
assuming that's right (and let me know if it is not)
should I
a) try to access the 'document' of the widget using some roundabout way (possibly with metatags?)
OR
b) there is no simple, all-encompassing way of performing the above, and I should ask the hosting site specifically how to access the widget and it's elements?
FALL3N
Junior Poster in Training
84 posts since May 2010
Reputation Points: 10
Solved Threads: 2
Why you're trying to pass the value as function argument. If you know the ID of the field, then, you can easily get the value within the function.
Example:
function goNow(){
var input = document.getElementById('theName').value;
// do your statement
}
Binding event that function without argumentonClick="goNow()"
It should work.
Zero13
Practically a Master Poster
624 posts since Jan 2009
Reputation Points: 120
Solved Threads: 139
that's a very good point, I'll do that, thanks!
FALL3N
Junior Poster in Training
84 posts since May 2010
Reputation Points: 10
Solved Threads: 2
ahh, yes, that is a better programming practice, thank you!
FALL3N
Junior Poster in Training
84 posts since May 2010
Reputation Points: 10
Solved Threads: 2