...

View Full Version : Resolved Passing HTML values as parameters for JavaScript function



luisoscarb
09-25-2008, 07:46 PM
Hello,

I posted a thread two days ago (before the the database rolled back) about passing parameters from ASP to JavaScript. I was able to go around that problem thanks to the user ess, but I have stumbled upon another issue.

I have code in ASP that loops over HTML code, repeating the following snippet of code:


<input type="text" name="input_A(##)" />
<input type="text" name="input_B(##)" />

<input type="button" value="Func" name="Button" onclick="javascript: TestFunction(this.form.input_A(##).value, this.form.input_B(##).value);"/>

Note: The ## implies that a number goes there. The code increases those values starting from 0, 1, 2, ... , n.

The function it calls is located here:

<script type="text/javascript">
function TestFunction(inp_A, inp_B) {
window.alert(inp_A + inp_B); //prints out inp_A and inp_B concatenated
}
</script>

It doesn't work when I pass it with the numbers attached, but otherwise, it works just fine:


<input type="text" name="input_A" /> //no array values
<input type="text" name="input_B" />

<input type="button" value="Func" name="Button" onclick="javascript: TestFunction(this.form.input_A.value, this.form.input_B.value);"/>


I know the array is able to store accurate values [another page gets them when I use request.form(input_A(##)) ]so I assumed there wouldn't have been a problem with my code. Nonetheless, it's not working. Is there any way to fix this?

Thanks!

luis

shyam
09-25-2008, 08:38 PM
<input type="text" name="input_A(##)" />
<input type="text" name="input_B(##)" />

<input type="button" value="Func" name="Button" onclick="javascript: TestFunction(this.form.input_A(##).value, this.form.input_B(##).value);"/>


what is interpreted by the browser is that you are calling a function input_A on the form object...and then accessing the value of the result...if you really want to have brackets in your form elements names use the array notation to access the form elements like this


TestFunction(this.form['input_A(##)'].value, this.form['input_B(##)'].value);

luisoscarb
09-25-2008, 09:37 PM
Thanks for the help! I was actually able to figure out what to do. Rather than giving it an array, such as "Input_A(##)", I decided to just concatenate them so that the name is actually "Input_A##". That way, it reads it as

this.form.Input_A##.value

instead of

this.form.Input_A(##).value

That ended up working!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum