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

Text Field Value

Status
Not open for further replies.

aarushi2001

Technical User
Nov 16, 2005
109
US
Hi, I have a form. The default value of text field is 'search'. Every time a user enters some value and hits enter I want to update the value of the text filed.

I cant use dynamic languages. Is it possible to use JavaScript DOM? How?

Thanks
 
Show what you have so far so we can get a better idea of what you're working with.

Lee
 
<script="javacript">
changeText() {
var cbOnject = window.form1.query1.value;
window.form1.query1.value = cbOnject;
}
</script>

<form name="form1" action="" method="get">
<input type="text" name="query1" value="search">
<input type="image" src="" onclick="changeText()">
</form>

I realised the problem is of having image instead of button.. just cant resolve..
 
clFlava...

I have textfield with default value="SEARCH". When I type something e.g. 'hello', the default value should change to 'hello'. However, I am still getting 'search'. I need to change the default value or if possible when I hit the submit, on next page I need the text box value as a hidden field.
 
If you just submit the form after typing something new in, you'll find that the value for the textbox actually becomes whatever you typed in. What you're doing with the Javascript function makes no sense at all.

Lee
 
The "default value" is the one you type into the HTML code, not necessarily the one that gets passed to the script that processes the form.

Please show us more of the code that you have. Copy and paste it in here, don't type it in or make up an example for us to see.

Lee
 
function putHeader() {

headerCode = "<div id=\"header\">"
+ "<div id=\"actions\">"
+ "<a class=\"accounts\" href=\"\">SIGN IN</a> <img class=\"sep\" width=\"5\" height=\"5\" src=\" <a class=\"accounts\" href=\"\">REGISTER</a><br />"
+ "<a id=\"download\" href=\"\">DOWNLOAD TOOLBAR</a>"
+ "</div>"
+ "<img id=\"logo\" src=\" width=\"153\" height=\"62\" alt=\"Gotuit Media: Don't Just Watch It. Gotuit. (TM)\" />"
+ "<form name=\"form1\" action=\" method=\"GET\" >"
+ "<img src=\" width=\"155\" height=\"15\" alt=\"Find It Here. Find It Now.\" />"
+ "<div id=\"search_box\">"
+ "<input type=\"hidden\" name=\"Op\" value=\"search\"/>"
+ "<input type=\"hidden\" name=\"operator\" value=\"gotuit\"/>"
+ "<input type=\"hidden\" name=\"results\" value=\"10\"/>"
+ "<input type=\"hidden\" name=\"query1\" value=\"most recent scenes\"/>"
+ "<input id=\"search\" type=\"text\" name=\"query\" value=\"search\" />"
+ "<input type=\"image\" width=\"39\" height=\"50\" alt=\"search\" src=\" />"

+ "</div>"
+ "</form>"
+ "</div>"
...
}

I have attached the JavaScript. This JS is the 'top' page.

I know 'default' value is the one we type in the html code. I just want to update/set 'default' value, whenever user hits the submit.
 
In other words, you want to rewrite that piece of Javascript, or somehow insert the new value when the page reloads? For that you need to either use cookies to insert the value after the page loads or server-side scripting to write the JS.

Lee
 
unfortunately I cant use server-side scripting :(((((

how can I use cookies?? any idea??
 
Try a Google search for Javascript cookies. When the form is submitted, create a cookie and place the new value in it. When the page loads, check to see if there's a cookie there and insert the value.

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top