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

Read form value without submitting

Status
Not open for further replies.

Sivagami

Programmer
Dec 11, 2000
14
US

Hi, Is there away to read the values in an Input form without Posting it (on a button click) and then assign values to some other fields based on the values inputted, all on client side ?

Thanks,
Shiva.
 
here's some examples

<script>
function declareFlds1(obj) {
document.frm.txt2.value = obj.value;
}
function declareFlds2(obj) {
document.frm.txt2.value = obj;
}
</script>

<form name=&quot;frm&quot;>
onBlur event
<input type=&quot;text&quot; name=&quot;txt1&quot; onBlur=&quot;declareFlds1(this)&quot;>
<input type=&quot;text&quot; name=&quot;txt2&quot;>
or button
<input type=&quot;button&quot; value=&quot;see it&quot; onClick=&quot;declareFlds2(document.frm.txt1.value)&quot;>
</form> ---------------------------------------
{ str = &quot;sleep is good for you. sleep gives you the energy you need to function&quot;;
ptr = /sleep/gi;Nstr = str.replace(ptr,&quot;coffee&quot;);alert(Nstr); }
---------------------------------------
for the best results to your questions: FAQ333-2924

 
Thanks a lot for your instant reply. This is exactly what I had been looking for.

Shiva.
 
Is it possible to do this with dynamic parameters for the function. Since my fields are dynamically generated, like
<%
for i = 1 to 12
for j = 1 to 12 %>
<TD width=35><font face='Arial,Helvetica' size='2'>
<input type=text name=expense_<%=i%>_<%=j%>>
</font></TD>
<%next %>
</TR><TR>
<%next %>

and I do not know how many fields are there or what their names are ??

Shiva.
 
I am presuming you have a dynamically generated form, probably based on a data base query. If that is so than this is how I would go about it.

Step 1. Generate the specific input tags you want to deal with by labelling them with a common class name and a consistent id attribute.

<input type=&quot;Text&quot; id=&quot;#loopcounter#visible&quot; class=&quot;findTheseOnes&quot;>
<input type=&quot;Hidden&quot; id=&quot;hidden#loopcounter#&quot;>

Step 2. Use the tags() function to get a collection of all the input fields on the form.

var bigColletion = document.all.tags(&quot;INPUT&quot;);

Step 3. Use the className property to filter the list down to just the fields you are interested in.

for(i=0; i<bigColletion.length; i++)
{
if(bigCollection.item.className == &quot;findTheseOnes&quot;)
{
//What is the number
tmp = parseInt(bigCollection.item(i).id);

//Perform required manipulations
newvalue = bigCollection.item(i).value + 1;

//Transfer values from visible to hidden
target = eval(&quot;document.all.hidden&quot; + tmp);
target.value = newvalue;
}
}

I am posting a complete working test file below if you want to give it a whirl.

<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;>
<html>
<head>
<title>Untitled</title>

<script type=&quot;text/javascript&quot;>
function CheckForm()
{
var bigCollection = document.all.tags(&quot;INPUT&quot;);
for(i=0; i<bigCollection.length; i++)
{
if(bigCollection.item(i).className == &quot;findTheseOnes&quot;)
{
//What is the number
tmp = parseInt(bigCollection.item(i).id);
//Perform required manipulations
newvalue = bigCollection.item(i).value + 1;
//Transfer values from visible to hidden
target = eval(&quot;document.all.hidden&quot; + tmp);
target.value = newvalue;
}
}
}
</script>
</head>

<body>
<form>
<input type=&quot;Text&quot; class=&quot;findTheseOnes&quot; id=&quot;0visible&quot;><input type=&quot;Text&quot; id=&quot;hidden0&quot;><br>
<input type=&quot;Text&quot; class=&quot;findTheseOnes&quot; id=&quot;1visible&quot;><input type=&quot;Text&quot; id=&quot;hidden1&quot;><br>
<input type=&quot;Text&quot; class=&quot;findTheseOnes&quot; id=&quot;2visible&quot;><input type=&quot;Text&quot; id=&quot;hidden2&quot;><br>
<input type=&quot;Button&quot; value=&quot;Submit&quot; onclick=&quot;CheckForm()&quot;>
</form>
</body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top