Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 20th, 2006, 10:35 PM
Authorized User
 
Join Date: Jul 2003
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to modify hidden value?

I have a HTML file,there are hidden parameter in in this HTML,hidden parameter name is made of "test"+number,such as
<form name="test" id="test">
 <input type="hidden" name="test0" value="9">
 <input type="hidden" name="test1" value="5">
 <input type="hidden" name="test2" value="6">
 <input type="hidden" name="test3" value="1">
</form>

I want to dynamic modify the hidden value,for example
i=3 //the value of i is get dynamic,i=2 or i=3 or any number
test.test<i>.value="99"
I know above sentence is error,how to write it correctly?

Thanks!


 
Old January 21st, 2006, 01:18 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

Hii Edward King!!

Use

eval("document.formname.textboxname"+i).value=new_ value
in ur case
eval("document.test.test"+i).value=newvalue
<script>
function setHiddenValue(obj)
{
value1=obj.value
eval("document.test.test"+value1).value=value1;
}
</script>
<form name="test" id="test">
 <input type="text" name="test0" value="9">
 <input type="text" name="test1" value="5">
 <input type="text" name="test2" value="6">
 <input type="text" name="test3" value="1">
<select name="val" onchange="setHiddenValue(this)">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</form>

Change type=text to hidden in ur code
hope this will help you



Cheers :)

vinod
 
Old January 21st, 2006, 05:44 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

In my opinion anyone who uses "eval" for a task like this should be drummed out of the programmers guild.
Code:
function setElementValue(FormName, ElementName, Value)
{
  document.forms[FormName].elements[ElementName].value = Value;
}
//Example
setElementValue("test", "test" + 3, 99);

--

Joe (Microsoft MVP - XML)





Similar Threads
Thread Thread Starter Forum Replies Last Post
i want to modify the shopping ssomchai BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 1 April 3rd, 2008 01:52 AM
Help Modify GetThreadsRss kherrerab BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 2 January 22nd, 2008 12:14 PM
Modify XSLT mikeymikey XSLT 4 January 5th, 2008 11:21 PM
How to modify "for-each" to "last occurrence of" ? nyctechwriter XSLT 3 October 30th, 2006 01:15 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.