Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Sep 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Passing HTML values as parameters for JavaScript function

    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:
    PHP 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:
    PHP Code:
    <script type="text/javascript">
        function 
    TestFunction(inp_Ainp_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:
    PHP Code:
    <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
    Last edited by luisoscarb; 09-25-2008 at 08:43 PM.

  • #2
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    Quote Originally Posted by luisoscarb View Post
    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);"/>
    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

    Code:
    TestFunction(this.form['input_A(##)'].value, this.form['input_B(##)'].value);
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow

  • #3
    New to the CF scene
    Join Date
    Sep 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •