This is the code I have:
Basically, I want to clear the text in the textbox onFocus, but only if the value of the textbox is 'name'.HTML Code:<input type="text" value="name" name="name" onfocus="if(this.value='name'){this.value=' '}">
Hellpppp?
Printable View
This is the code I have:
Basically, I want to clear the text in the textbox onFocus, but only if the value of the textbox is 'name'.HTML Code:<input type="text" value="name" name="name" onfocus="if(this.value='name'){this.value=' '}">
Hellpppp?
Example here: http://unedible.com/textbox.html
It works halfway- it clears the text...but always instead of only when a certain value is present.
First of all, you are putting a space in the textbox. You know that you can actually clear it with an empty string ""?
The equality check is ==, two ='s. Assignment, one thing is equal to another, is one =.
Oh. I knew about the space, I just put it there so on the post you could tell the differece between two ' and ". I got it working anyway, actually. I have one more issue concerning form submission, though.
and the html isCode:function submitForm(){
var name = document.getElementById ('name');
document.write('Name:' + name);
}
This doesn't seem to be working. D:Code:<form name="form" onSubmit="submitForm()">
<input type="text" value="name" name="name" id="name" onfocus="clearMe(this)">
</form>
I'm guessing your page goes blank and only displays the name object?
Are you trying to validate the name field here? (name.value)
document.write clears the entire page if you call it when the page is finished loading. Try alert instead to check the value.
Also you are not returning a true/false value from submitForm() ;
And you are not returning the results of submitForm() to the actual form: onsubmit="return submitForm();"
What happens in Google Chrome is...nothing, except the address bar adds on a ?name=John&email=myname@domain.com, ect. In Firefox you see a Name: and either blank space or the word null.
What do you want it to do, and I will change the code to do just that.
Display the entered content on the page. I've done this before, it's just not seeming to work now. I'm not that great at Javascript. ;___;
Something like:
HTML Code:<script type="text/javascript">
function submitForm(){
var name = document.getElementById('name');
document.getElementById("results").innerHTML = 'Name: ' + name.value;
//document.write('Name:' + name);
return false;
}
function clearMe() {}
</script>
<form name="form" onSubmit="return submitForm();">
<input type="text" value="name" name="name" id="name" onfocus="clearMe(this);">
<input type="submit" />
</form>
<div id="results"></div>
The result flashes, but then goes away. Help?
Did you change your form to return the value (which is false), otherwise it will just post the data?
You also need to return false from the submitForm() function;HTML Code:<form name="form" onSubmit="return submitForm();">
AHA! That worked! Thanks so much. :D