'Moving a value into an html form field
I am very new to JavaScript and would like to know how to go about the following. I have a form that I am using for entry to a fishing contest. It contains fields for up to six anglers but they only fill out two. What I am attempting to do is where a contest is declared via the form I add a value (the entry fee) to a hidden field on the form.
Like:
if form.anglername1 <> "" then form.angler1fee = "75"
Have tried various methods I have seen on the web without success. Having said that I really don't know what I am doing.
Have been a Clarion coder for too many years to talk about and am finding JavaScript just a little tough. If anyone can help a little I would be very happy.
Solution 1:[1]
Without seeing more code, I'm not sure exactly how to do what you want, but the snippet you gave isn't JavaScript. Here is the proper JS syntax for what you have written.
if(form.anglename1 != ""){
form.anglerfee = "75";
}
Solution 2:[2]
why to add an hidden field? try this with your input field:
<input name="anglername1" onblur="this.value=this.value==''?'75':this.value;"
onfocus="this.value = this.value == this.defaultValue? '' : this.value;" />
HTH !
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | David |
Solution 2 |